/** * Write LONG. * using little-endian to write double. * * @param l the l * @throws IOException the io exception */ public void writeLong(long l) throws IOException { EndianUtils.writeSwappedLong(this, l); }
/** * Writes a "double" value to a byte array at a given offset. The value is * converted to the opposed endian system while writing. * @param data target byte array * @param offset starting offset in the byte array * @param value value to write */ public static void writeSwappedDouble(final byte[] data, final int offset, final double value) { writeSwappedLong( data, offset, Double.doubleToLongBits( value ) ); }
/** * Writes a "double" value to an OutputStream. The value is * converted to the opposed endian system while writing. * @param output target OutputStream * @param value value to write * @throws IOException in case of an I/O problem */ public static void writeSwappedDouble(final OutputStream output, final double value) throws IOException { writeSwappedLong( output, Double.doubleToLongBits( value ) ); }
/** * Writes a "double" value to an OutputStream. The value is * converted to the opposed endian system while writing. * @param output target OutputStream * @param value value to write * @throws IOException in case of an I/O problem */ public static void writeSwappedDouble(OutputStream output, double value) throws IOException { writeSwappedLong( output, Double.doubleToLongBits( value ) ); }
/** * Writes a "double" value to a byte array at a given offset. The value is * converted to the opposed endian system while writing. * @param data target byte array * @param offset starting offset in the byte array * @param value value to write */ public static void writeSwappedDouble(byte[] data, int offset, double value) { writeSwappedLong( data, offset, Double.doubleToLongBits( value ) ); }
@Test public void testSymmetryOfLong() { final double[] tests = new double[] {34.345, -345.5645, 545.12, 10.043, 7.123456789123}; for (final double test : tests) { // testing the real problem byte[] buffer = new byte[8]; final long ln1 = Double.doubleToLongBits( test ); EndianUtils.writeSwappedLong(buffer, 0, ln1); final long ln2 = EndianUtils.readSwappedLong(buffer, 0); assertEquals( ln1, ln2 ); // testing the bug report buffer = new byte[8]; EndianUtils.writeSwappedDouble(buffer, 0, test); final double val = EndianUtils.readSwappedDouble(buffer, 0); assertEquals( test, val, 0 ); } }
@Test public void testWriteSwappedLong() throws IOException { byte[] bytes = new byte[8]; EndianUtils.writeSwappedLong( bytes, 0, 0x0102030405060708L ); assertEquals( 0x08, bytes[0] ); assertEquals( 0x07, bytes[1] ); assertEquals( 0x06, bytes[2] ); assertEquals( 0x05, bytes[3] ); assertEquals( 0x04, bytes[4] ); assertEquals( 0x03, bytes[5] ); assertEquals( 0x02, bytes[6] ); assertEquals( 0x01, bytes[7] ); final ByteArrayOutputStream baos = new ByteArrayOutputStream(8); EndianUtils.writeSwappedLong( baos, 0x0102030405060708L ); bytes = baos.toByteArray(); assertEquals( 0x08, bytes[0] ); assertEquals( 0x07, bytes[1] ); assertEquals( 0x06, bytes[2] ); assertEquals( 0x05, bytes[3] ); assertEquals( 0x04, bytes[4] ); assertEquals( 0x03, bytes[5] ); assertEquals( 0x02, bytes[6] ); assertEquals( 0x01, bytes[7] ); }
public void writeLong(long v) throws IOException { EndianUtils.writeSwappedLong(stream, v); }
/** * Writes a "double" value to a byte array at a given offset. The value is * converted to the opposed endian system while writing. * @param data target byte array * @param offset starting offset in the byte array * @param value value to write */ public static void writeSwappedDouble(final byte[] data, final int offset, final double value) { writeSwappedLong( data, offset, Double.doubleToLongBits( value ) ); }
/** * Writes a "double" value to an OutputStream. The value is * converted to the opposed endian system while writing. * @param output target OutputStream * @param value value to write * @throws IOException in case of an I/O problem */ public static void writeSwappedDouble(OutputStream output, double value) throws IOException { writeSwappedLong( output, Double.doubleToLongBits( value ) ); }
/** * Writes a "double" value to an OutputStream. The value is * converted to the opposed endian system while writing. * @param output target OutputStream * @param value value to write * @throws IOException in case of an I/O problem */ public static void writeSwappedDouble(OutputStream output, double value) throws IOException { writeSwappedLong( output, Double.doubleToLongBits( value ) ); }
/** * Writes a "double" value to a byte array at a given offset. The value is * converted to the opposed endian system while writing. * @param data target byte array * @param offset starting offset in the byte array * @param value value to write */ public static void writeSwappedDouble(byte[] data, int offset, double value) { writeSwappedLong( data, offset, Double.doubleToLongBits( value ) ); }
/** * Writes a "double" value to a byte array at a given offset. The value is * converted to the opposed endian system while writing. * @param data target byte array * @param offset starting offset in the byte array * @param value value to write */ public static void writeSwappedDouble(byte[] data, int offset, double value) { writeSwappedLong( data, offset, Double.doubleToLongBits( value ) ); }
/** * Writes a "double" value to a byte array at a given offset. The value is * converted to the opposed endian system while writing. * @param data target byte array * @param offset starting offset in the byte array * @param value value to write */ public static void writeSwappedDouble(byte[] data, int offset, double value) { writeSwappedLong( data, offset, Double.doubleToLongBits( value ) ); }
/** * Writes a "double" value to an OutputStream. The value is * converted to the opposed endian system while writing. * @param output target OutputStream * @param value value to write * @throws IOException in case of an I/O problem */ public static void writeSwappedDouble(final OutputStream output, final double value) throws IOException { writeSwappedLong( output, Double.doubleToLongBits( value ) ); }
/** * Writes a "double" value to an OutputStream. The value is * converted to the opposed endian system while writing. * @param output target OutputStream * @param value value to write * @throws IOException in case of an I/O problem */ public static void writeSwappedDouble(OutputStream output, double value) throws IOException { writeSwappedLong( output, Double.doubleToLongBits( value ) ); }
/** * Writes a "double" value to a byte array at a given offset. The value is * converted to the opposed endian system while writing. * @param data target byte array * @param offset starting offset in the byte array * @param value value to write */ public static void writeSwappedDouble(byte[] data, int offset, double value) { writeSwappedLong( data, offset, Double.doubleToLongBits( value ) ); }
/** * Writes a "double" value to an OutputStream. The value is * converted to the opposed endian system while writing. * @param output target OutputStream * @param value value to write * @throws IOException in case of an I/O problem */ public static void writeSwappedDouble(OutputStream output, double value) throws IOException { writeSwappedLong( output, Double.doubleToLongBits( value ) ); }
/** * Writes a "double" value to a byte array at a given offset. The value is * converted to the opposed endian system while writing. * @param data target byte array * @param offset starting offset in the byte array * @param value value to write */ public static void writeSwappedDouble(final byte[] data, final int offset, final double value) { writeSwappedLong( data, offset, Double.doubleToLongBits( value ) ); }
/** * Writes a "double" value to an OutputStream. The value is * converted to the opposed endian system while writing. * @param output target OutputStream * @param value value to write * @throws IOException in case of an I/O problem */ public static void writeSwappedDouble(final OutputStream output, final double value) throws IOException { writeSwappedLong( output, Double.doubleToLongBits( value ) ); }