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 )
|
public static int writeToStream( final OutputStream out, final short n )
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
final int length = LittleEndian.SHORT_SIZE;
|
LittleEndian.putShort( out, n ); // FIXME: unsigned
|
||||||
byte[] buffer = new byte[length];
|
return LittleEndian.SHORT_SIZE;
|
||||||
LittleEndian.putShort(buffer, 0, n); // FIXME: unsigned
|
|
||||||
out.write(buffer, 0, length);
|
|
||||||
return length;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Writes a four-byte value to an output stream.</p>
|
* <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 )
|
public static int writeToStream( final OutputStream out, final int n )
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
final int l = LittleEndian.INT_SIZE;
|
LittleEndian.putInt( n, out );
|
||||||
final byte[] buffer = new byte[l];
|
return LittleEndian.INT_SIZE;
|
||||||
LittleEndian.putInt(buffer, 0, n);
|
|
||||||
out.write(buffer, 0, l);
|
|
||||||
return l;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Writes a eight-byte value to an output stream.</p>
|
* <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 )
|
public static int writeToStream( final OutputStream out, final long n )
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
final int l = LittleEndian.LONG_SIZE;
|
LittleEndian.putLong( n, out );
|
||||||
final byte[] buffer = new byte[l];
|
return LittleEndian.LONG_SIZE;
|
||||||
LittleEndian.putLong(buffer, 0, n);
|
|
||||||
out.write(buffer, 0, l);
|
|
||||||
return l;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Writes an unsigned two-byte value to an output stream.</p>
|
* <p>Writes an unsigned two-byte value to an output stream.</p>
|
||||||
*
|
*
|
||||||
@ -105,13 +88,11 @@ public class TypeWriter
|
|||||||
{
|
{
|
||||||
int high = n & 0xFFFF0000;
|
int high = n & 0xFFFF0000;
|
||||||
if ( high != 0 )
|
if ( high != 0 )
|
||||||
throw new IllegalPropertySetDataException
|
throw new IllegalPropertySetDataException( "Value " + n
|
||||||
("Value " + n + " cannot be represented by 2 bytes.");
|
+ " cannot be represented by 2 bytes." );
|
||||||
writeToStream(out, (short) n);
|
LittleEndian.putUShort( n, out );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Writes an unsigned four-byte value to an output stream.</p>
|
* <p>Writes an unsigned four-byte value to an output stream.</p>
|
||||||
*
|
*
|
||||||
@ -125,13 +106,12 @@ public class TypeWriter
|
|||||||
{
|
{
|
||||||
long high = n & 0xFFFFFFFF00000000L;
|
long high = n & 0xFFFFFFFF00000000L;
|
||||||
if ( high != 0 && high != 0xFFFFFFFF00000000L )
|
if ( high != 0 && high != 0xFFFFFFFF00000000L )
|
||||||
throw new IllegalPropertySetDataException
|
throw new IllegalPropertySetDataException( "Value " + n
|
||||||
("Value " + n + " cannot be represented by 4 bytes.");
|
+ " cannot be represented by 4 bytes." );
|
||||||
return writeToStream(out, (int) n);
|
LittleEndian.putUInt( n, out );
|
||||||
|
return LittleEndian.INT_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Writes a 16-byte {@link ClassID} to an output stream.</p>
|
* <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 )
|
public static int writeToStream( final OutputStream out, final double n )
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
final int l = LittleEndian.DOUBLE_SIZE;
|
LittleEndian.putDouble( n, out );
|
||||||
final byte[] buffer = new byte[l];
|
return LittleEndian.DOUBLE_SIZE;
|
||||||
LittleEndian.putDouble(buffer, 0, n);
|
|
||||||
out.write(buffer, 0, l);
|
|
||||||
return l;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user