reuse code from LittleEndian class
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1187549 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4ef78d40fc
commit
a35cf979d2
@ -42,15 +42,10 @@ public class TypeWriter
|
||||
public static int writeToStream( final OutputStream out, final short n )
|
||||
throws IOException
|
||||
{
|
||||
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;
|
||||
LittleEndian.putShort( out, n ); // FIXME: unsigned
|
||||
return LittleEndian.SHORT_SIZE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <p>Writes a four-byte value to an output stream.</p>
|
||||
*
|
||||
@ -62,16 +57,10 @@ public class TypeWriter
|
||||
public static int writeToStream( final OutputStream out, final int n )
|
||||
throws IOException
|
||||
{
|
||||
final int l = LittleEndian.INT_SIZE;
|
||||
final byte[] buffer = new byte[l];
|
||||
LittleEndian.putInt(buffer, 0, n);
|
||||
out.write(buffer, 0, l);
|
||||
return l;
|
||||
|
||||
LittleEndian.putInt( n, out );
|
||||
return LittleEndian.INT_SIZE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <p>Writes a eight-byte value to an output stream.</p>
|
||||
*
|
||||
@ -83,16 +72,10 @@ public class TypeWriter
|
||||
public static int writeToStream( final OutputStream out, final long n )
|
||||
throws IOException
|
||||
{
|
||||
final int l = LittleEndian.LONG_SIZE;
|
||||
final byte[] buffer = new byte[l];
|
||||
LittleEndian.putLong(buffer, 0, n);
|
||||
out.write(buffer, 0, l);
|
||||
return l;
|
||||
|
||||
LittleEndian.putLong( n, out );
|
||||
return LittleEndian.LONG_SIZE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <p>Writes an unsigned two-byte value to an output stream.</p>
|
||||
*
|
||||
@ -105,13 +88,11 @@ public class TypeWriter
|
||||
{
|
||||
int high = n & 0xFFFF0000;
|
||||
if ( high != 0 )
|
||||
throw new IllegalPropertySetDataException
|
||||
("Value " + n + " cannot be represented by 2 bytes.");
|
||||
writeToStream(out, (short) n);
|
||||
throw new IllegalPropertySetDataException( "Value " + n
|
||||
+ " cannot be represented by 2 bytes." );
|
||||
LittleEndian.putUShort( n, out );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <p>Writes an unsigned four-byte value to an output stream.</p>
|
||||
*
|
||||
@ -125,13 +106,12 @@ public class TypeWriter
|
||||
{
|
||||
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);
|
||||
throw new IllegalPropertySetDataException( "Value " + n
|
||||
+ " cannot be represented by 4 bytes." );
|
||||
LittleEndian.putUInt( n, out );
|
||||
return LittleEndian.INT_SIZE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <p>Writes a 16-byte {@link ClassID} to an output stream.</p>
|
||||
*
|
||||
@ -203,11 +183,8 @@ public class TypeWriter
|
||||
public static int writeToStream( final OutputStream out, final double n )
|
||||
throws IOException
|
||||
{
|
||||
final int l = LittleEndian.DOUBLE_SIZE;
|
||||
final byte[] buffer = new byte[l];
|
||||
LittleEndian.putDouble(buffer, 0, n);
|
||||
out.write(buffer, 0, l);
|
||||
return l;
|
||||
LittleEndian.putDouble( n, out );
|
||||
return LittleEndian.DOUBLE_SIZE;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user