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
@ -39,18 +39,13 @@ public class TypeWriter
|
||||
* @return The number of bytes that have been written.
|
||||
* @exception IOException if an I/O error occurs
|
||||
*/
|
||||
public static int writeToStream(final OutputStream out, final short n)
|
||||
throws IOException
|
||||
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>
|
||||
*
|
||||
@ -59,40 +54,28 @@ public class TypeWriter
|
||||
* @exception IOException if an I/O error occurs
|
||||
* @return The number of bytes written to the output stream.
|
||||
*/
|
||||
public static int writeToStream(final OutputStream out, final int n)
|
||||
throws IOException
|
||||
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>
|
||||
*
|
||||
* @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.
|
||||
* @return The number of bytes written to the output stream.
|
||||
*/
|
||||
public static int writeToStream(final OutputStream out, final long n)
|
||||
throws IOException
|
||||
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>
|
||||
*
|
||||
@ -100,18 +83,16 @@ public class TypeWriter
|
||||
* @param n The value to write
|
||||
* @exception IOException if an I/O error occurs
|
||||
*/
|
||||
public static void writeUShortToStream(final OutputStream out, final int n)
|
||||
throws IOException
|
||||
public static void writeUShortToStream( final OutputStream out, final int n )
|
||||
throws IOException
|
||||
{
|
||||
int high = n & 0xFFFF0000;
|
||||
if (high != 0)
|
||||
throw new IllegalPropertySetDataException
|
||||
("Value " + n + " cannot be represented by 2 bytes.");
|
||||
writeToStream(out, (short) n);
|
||||
if ( high != 0 )
|
||||
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>
|
||||
*
|
||||
@ -120,18 +101,17 @@ public class TypeWriter
|
||||
* @return The number of bytes that have been written to the output stream.
|
||||
* @exception IOException if an I/O error occurs
|
||||
*/
|
||||
public static int writeUIntToStream(final OutputStream out, final long n)
|
||||
throws IOException
|
||||
public static int writeUIntToStream( final OutputStream out, final long n )
|
||||
throws IOException
|
||||
{
|
||||
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);
|
||||
if ( high != 0 && high != 0xFFFFFFFF00000000L )
|
||||
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>
|
||||
*
|
||||
@ -200,14 +180,11 @@ public class TypeWriter
|
||||
* @exception IOException if an I/O error occurs
|
||||
* @return The number of bytes written to the output stream.
|
||||
*/
|
||||
public static int writeToStream(final OutputStream out, final double n)
|
||||
throws IOException
|
||||
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