/** * Write INT. * using little-endian to write integer. * * @param i the * @throws IOException the io exception */ public void writeInt(int i) throws IOException { EndianUtils.writeSwappedInteger(this, i); }
/** * Writes a "float" 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 writeSwappedFloat(final byte[] data, final int offset, final float value) { writeSwappedInteger( data, offset, Float.floatToIntBits( value ) ); }
/** * Writes a "float" 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 writeSwappedFloat(final OutputStream output, final float value) throws IOException { writeSwappedInteger( output, Float.floatToIntBits( value ) ); }
/** * Writes a "float" 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 writeSwappedFloat(byte[] data, int offset, float value) { writeSwappedInteger( data, offset, Float.floatToIntBits( value ) ); }
/** * Writes a "float" 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 writeSwappedFloat(OutputStream output, float value) throws IOException { writeSwappedInteger( output, Float.floatToIntBits( value ) ); }
@Override public void write(Writable r) throws IOException { BytesWritable bw = (BytesWritable) r; int recordLength = bw.getLength(); //Based on the row length to decide if the length is int or short String rowLength = tableProperties .getProperty(TeradataBinaryRecordReader.TD_ROW_LENGTH, TeradataBinaryRecordReader.DEFAULT_TD_ROW_LENGTH) .toLowerCase(); LOG.debug(format("The table property %s is: %s", TeradataBinaryRecordReader.TD_ROW_LENGTH, rowLength)); if (TeradataBinaryRecordReader.TD_ROW_LENGTH_TO_BYTE_NUM.containsKey(rowLength)) { if (rowLength.equals(TeradataBinaryRecordReader.DEFAULT_TD_ROW_LENGTH)) { EndianUtils.writeSwappedShort(outStream, (short) recordLength); // write the length using little endian } else if (rowLength.equals(TeradataBinaryRecordReader.TD_ROW_LENGTH_1MB)) { EndianUtils.writeSwappedInteger(outStream, recordLength); // write the length using little endian } } else { throw new IllegalArgumentException(format("%s doesn't support the value %s, the supported values are %s", TeradataBinaryRecordReader.TD_ROW_LENGTH, rowLength, TeradataBinaryRecordReader.TD_ROW_LENGTH_TO_BYTE_NUM.keySet())); } outStream.write(bw.getBytes(), 0, bw.getLength()); // write the content (the content is in little endian) outStream.write(RECORD_END_BYTE); //write the record ending }
/** * Write DATE. * The representation of date in Teradata binary format is: * The Date D is a int with 4 bytes using little endian. * The representation is (YYYYMMDD - 19000000).toInt -> D * eg. 1911.11.11 -> 19111111 -> 111111 -> 07 b2 01 00 in little endian. * the null date will use 0 to pad. * * @param date the date * @throws IOException the io exception */ public void writeDate(DateWritableV2 date) throws IOException { if (date == null) { EndianUtils.writeSwappedInteger(this, 0); return; } int toWrite = date.get().getYear() * 10000 + date.get().getMonth() * 100 + date.get().getDay() - 19000000; EndianUtils.writeSwappedInteger(this, toWrite); }
@Test public void testWriteSwappedInteger() throws IOException { byte[] bytes = new byte[4]; EndianUtils.writeSwappedInteger( bytes, 0, 0x01020304 ); assertEquals( 0x04, bytes[0] ); assertEquals( 0x03, bytes[1] ); assertEquals( 0x02, bytes[2] ); assertEquals( 0x01, bytes[3] ); final ByteArrayOutputStream baos = new ByteArrayOutputStream(4); EndianUtils.writeSwappedInteger( baos, 0x01020304 ); bytes = baos.toByteArray(); assertEquals( 0x04, bytes[0] ); assertEquals( 0x03, bytes[1] ); assertEquals( 0x02, bytes[2] ); assertEquals( 0x01, bytes[3] ); }
/** * Writes a "float" 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 writeSwappedFloat(byte[] data, int offset, float value) { writeSwappedInteger( data, offset, Float.floatToIntBits( value ) ); }
/** * Writes a "float" 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 writeSwappedFloat(OutputStream output, float value) throws IOException { writeSwappedInteger( output, Float.floatToIntBits( value ) ); }
/** * Writes a "float" 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 writeSwappedFloat(byte[] data, int offset, float value) { writeSwappedInteger( data, offset, Float.floatToIntBits( value ) ); }
/** * Writes a "float" 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 writeSwappedFloat(OutputStream output, float value) throws IOException { writeSwappedInteger( output, Float.floatToIntBits( value ) ); }
/** * Writes a "float" 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 writeSwappedFloat(OutputStream output, float value) throws IOException { writeSwappedInteger( output, Float.floatToIntBits( value ) ); }
/** * Writes a "float" 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 writeSwappedFloat(final OutputStream output, final float value) throws IOException { writeSwappedInteger( output, Float.floatToIntBits( value ) ); }
/** * Writes a "float" 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 writeSwappedFloat(byte[] data, int offset, float value) { writeSwappedInteger( data, offset, Float.floatToIntBits( value ) ); }
/** * Writes a "float" 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 writeSwappedFloat(final OutputStream output, final float value) throws IOException { writeSwappedInteger( output, Float.floatToIntBits( value ) ); }
/** * Writes a "float" 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 writeSwappedFloat(byte[] data, int offset, float value) { writeSwappedInteger( data, offset, Float.floatToIntBits( value ) ); }
/** * Writes a "float" 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 writeSwappedFloat(OutputStream output, float value) throws IOException { writeSwappedInteger( output, Float.floatToIntBits( value ) ); }
/** * Writes a "float" 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 writeSwappedFloat(final byte[] data, final int offset, final float value) { writeSwappedInteger( data, offset, Float.floatToIntBits( value ) ); }
/** * Writes a "float" 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 writeSwappedFloat(final byte[] data, final int offset, final float value) { writeSwappedInteger( data, offset, Float.floatToIntBits( value ) ); }