FileDocCategorySizeDatePackage
TypeWriter.javaAPI DocApache Poi 3.0.17019Mon Jan 01 12:39:34 GMT 2007org.apache.poi.hpsf

TypeWriter

public class TypeWriter extends Object

Class for writing little-endian data and more.

author
Rainer Klute <klute@rainer-klute.de>
version
$Id: TypeWriter.java 489730 2006-12-22 19:18:16Z bayard $
since
2003-02-20

Fields Summary
Constructors Summary
Methods Summary
public static intwriteToStream(java.io.OutputStream out, short n)

Writes a two-byte value (short) to an output stream.

param
out The stream to write to.
param
n The value to write.
return
The number of bytes that have been written.
exception
IOException if an I/O error occurs

        final int length = LittleEndian.SHORT_SIZE;
        byte[] buffer = new byte[length];
        LittleEndian.putShort(buffer, 0, n); // FIXME: unsigned
        out.write(buffer, 0, length);
        return length;
    
public static intwriteToStream(java.io.OutputStream out, int n)

Writes a four-byte value to an output stream.

param
out The stream to write to.
param
n The value to write.
exception
IOException if an I/O error occurs
return
The number of bytes written to the output stream.

        final int l = LittleEndian.INT_SIZE;
        final byte[] buffer = new byte[l];
        LittleEndian.putInt(buffer, 0, n);
        out.write(buffer, 0, l);
        return l;
        
    
public static intwriteToStream(java.io.OutputStream out, long n)

Writes a eight-byte value to an output stream.

param
out The stream to write to.
param
n The value to write.
exception
IOException if an I/O error occurs
return
The number of bytes written to the output stream.

        final int l = LittleEndian.LONG_SIZE;
        final byte[] buffer = new byte[l];
        LittleEndian.putLong(buffer, 0, n);
        out.write(buffer, 0, l);
        return l;
        
    
public static intwriteToStream(java.io.OutputStream out, org.apache.poi.hpsf.ClassID n)

Writes a 16-byte {@link ClassID} to an output stream.

param
out The stream to write to
param
n The value to write
return
The number of bytes written
exception
IOException if an I/O error occurs

        byte[] b = new byte[16];
        n.write(b, 0);
        out.write(b, 0, b.length);
        return b.length;
    
public static voidwriteToStream(java.io.OutputStream out, org.apache.poi.hpsf.Property[] properties, int codepage)

Writes an array of {@link Property} instances to an output stream according to the Horrible Property Stream Format.

param
out The stream to write to
param
properties The array to write to the stream
param
codepage The codepage number to use for writing strings
exception
IOException if an I/O error occurs
throws
UnsupportedVariantTypeException if HPSF does not support some variant type.

        /* If there are no properties don't write anything. */
        if (properties == null)
            return;

        /* Write the property list. This is a list containing pairs of property
         * ID and offset into the stream. */
        for (int i = 0; i < properties.length; i++)
        {
            final Property p = properties[i];
            writeUIntToStream(out, p.getID());
            writeUIntToStream(out, p.getSize());
        }

        /* Write the properties themselves. */
        for (int i = 0; i < properties.length; i++)
        {
            final Property p = properties[i];
            long type = p.getType();
            writeUIntToStream(out, type);
            VariantSupport.write(out, (int) type, p.getValue(), codepage);
        }
    
public static intwriteToStream(java.io.OutputStream out, double n)

Writes a double value value to an output stream.

param
out The stream to write to.
param
n The value to write.
exception
IOException if an I/O error occurs
return
The number of bytes written to the output stream.

        final int l = LittleEndian.DOUBLE_SIZE;
        final byte[] buffer = new byte[l];
        LittleEndian.putDouble(buffer, 0, n);
        out.write(buffer, 0, l);
        return l;
    
public static intwriteUIntToStream(java.io.OutputStream out, long n)

Writes an unsigned four-byte value to an output stream.

param
out The stream to write to.
param
n The value to write.
return
The number of bytes that have been written to the output stream.
exception
IOException if an I/O error occurs

        long high = n & 0xFFFFFFFF00000000L;
        if (high != 0 && high != 0xFFFFFFFF00000000L)
            throw new IllegalPropertySetDataException
                ("Value " + n + " cannot be represented by 4 bytes.");
        return writeToStream(out, (int) n);
    
public static voidwriteUShortToStream(java.io.OutputStream out, int n)

Writes an unsigned two-byte value to an output stream.

param
out The stream to write to
param
n The value to write
exception
IOException if an I/O error occurs

        int high = n & 0xFFFF0000;
        if (high != 0)
            throw new IllegalPropertySetDataException
                ("Value " + n + " cannot be represented by 2 bytes.");
        writeToStream(out, (short) n);