Have you tried as a long?
 -----Original Message-----
From: 	java400-l-bounces@xxxxxxxxxxxx [mailto:java400-l-bounces@xxxxxxxxxxxx]  On Behalf Of Steven Van Loon
Sent:	Wednesday, January 09, 2008 6:14 AM
To:	java400-l@xxxxxxxxxxxx
Subject:	Size of spooled file
Hi,
Does anybody ever tried to retrieve the size of a SpooledFile via the
Toolkit? According to the documentation, a PrintObject attribute exists,
ATTR_NUMBYTES_SPLF, which should give back the size as an integer
(
http://publib.boulder.ibm.com/iseries/v5r1/ic2924/info/rzahh/javadoc/Pr
intAttributes.html#HDRKEY174).
When I try to read it as an integer, I get an exception: 
ExtendedIllegalArgumentException: ATTR_NUMBYTES_SPLF: Parameter value is
not valid.
When I try to read it as a string, I get an Exception:
ExtendedIllegalArgumentException: ATTR_NUMBYTES_SPLF: Parameter value is
not valid.
When I try to read it as a float, I get a value (!), but I don't know
how to interpret this value. I have the following piece of code to
execute:
public class SplfAttributes
{
	public static void main(String[] args)
	{
		AS400 connection = new AS400(..., ..., ...);
		String file = ...;
		int number = ...;
		String job = ...;
		String jobuser = ...;
		String jobnumber = ...;
		SpooledFile splf = new SpooledFile(connection, file,
number, job, jobuser, jobnumber);
		// Get value as int
		int intValue;
		try
		{
			intValue =
splf.getIntegerAttribute(PrintObject.ATTR_NUMBYTES_SPLF).intValue();
			System.out.println("Int value = " + intValue);
		}
		catch (Exception ex)
		{
			System.out.println("Attribute is not an int");
		}
		// Get value as String
		String stringValue;
		try
		{
			stringValue =
splf.getStringAttribute(PrintObject.ATTR_NUMBYTES_SPLF);
			System.out.println("String value = " +
stringValue);
		}
		catch (Exception ex)
		{
			System.out.println("Attribute is not a string");
		}
		// Get value as float
		float floatValue;
		try
		{
			floatValue =
splf.getFloatAttribute(PrintObject.ATTR_NUMBYTES_SPLF).floatValue();
			System.out.println("float value = " +
floatValue);
		}
		catch (Exception ex)
		{
			System.out.println("Attribute is not a float");
		}
		try
		{
			// Calculate size by counting # bytes
			int calculatedSize = 0;
			PrintObjectInputStream str =
splf.getInputStream();
			byte[] buffer = new byte[1024];
			int bytes = str.read(buffer, 0, 1024);
			while (bytes > 0)
			{
				calculatedSize += bytes;
				bytes = str.read(buffer, 0, 1024);
			}
			System.out.println("Calculated size = " +
calculatedSize);
			str.close();
		}
		catch (Exception ex)
		{
			System.out.println("Exception during
calculation:"+ex.getMessage());
			ex.printStackTrace(System.out);
		}
	}
}
Executing the code produces the following output for some splf:
	Attribute is not an int
	Attribute is not a string
	float value = 36.018665
	Calculated size = 3602000
The size of the splf reported by 'WRKSPLFA FILE(...) JOB(.../.../...)
SPLNBR(...)' is 3656K.
How are these values related to each other? I see that 3602000 is
approximately 36.018665 times 10000 (10240 ?) but not exactly. 
Anybody ideas how these values are calculated? Is there another way to
get the size of a spooled file? (calculating it like in the code above
is not an option).
Best regards,
Steven.
As an Amazon Associate we earn from qualifying purchases.