Java Code Examples for java.nio.ByteOrder#nativeOrder()

The following examples show how to use java.nio.ByteOrder#nativeOrder() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Stat.java    From util with Apache License 2.0 6 votes vote down vote up
public static Stat fstat(FileDescriptor fd) throws IOException {
    NativeBuffer nativeBuffer = new NativeBuffer(92, ByteOrder.nativeOrder());
    try {
        DirectMemory direct = nativeBuffer.memory();
        try {
            int err = fstat(fdField.getInt(fd), direct.getAddress());
            if (err == errstr.indexOf("ENOENT")) {
                throw new FileNotFoundException("No such file or directory");
            }
            if (err != 0) {
                throw new IOException("fstat on file descriptor "+fd+" failed with error "+(err < 0 ? "unknown" : errstr.get(err)));
            }
        } catch (IllegalAccessException e) {
            throw Throwables.propagate(e);
        }
        return new Stat(direct);
    } finally {
        nativeBuffer.close();
    }
}
 
Example 2
Source File: TestMMapBuffer.java    From util with Apache License 2.0 6 votes vote down vote up
@Test
public void testMadviseDontNeedTrackedBuffers() throws IOException {
    try {
        MMapBuffer.setTrackingEnabled(false);
        MMapBuffer.madviseDontNeedTrackedBuffers();

        MMapBuffer.setTrackingEnabled(true);
        MMapBuffer.madviseDontNeedTrackedBuffers();

        final File tempFile = File.createTempFile("TestMMapBuffer", "");
        try (MMapBuffer ignored = new MMapBuffer(tempFile, 0, 10, FileChannel.MapMode.READ_WRITE, ByteOrder.nativeOrder())) {
            MMapBuffer.madviseDontNeedTrackedBuffers();
        }

        MMapBuffer.madviseDontNeedTrackedBuffers();
    } finally {
        MMapBuffer.setTrackingEnabled(false);
    }
}
 
Example 3
Source File: NumberToBinaryUtils.java    From yosegi with Apache License 2.0 6 votes vote down vote up
@Override
public IWriteSupporter toWriteSuppoter( final int rows , final byte[] buffer ,
    final int start , final int length ) throws IOException {
  int byteLength = Byte.BYTES * rows;
  int shortLength = Short.BYTES * rows;

  ByteOrder order = ByteOrder.nativeOrder();
  byte byteOrderByte = order == ByteOrder.BIG_ENDIAN ? (byte)0 : (byte)1;

  buffer[start] = HEADER_3;
  buffer[start + 1] = byteOrderByte;

  int byteStart = start + HEADER_SIZE;
  int shortStart = byteStart + byteLength;

  IWriteSupporter byteSupporter = ByteBufferSupporterFactory.createWriteSupporter(
      buffer , byteStart , byteLength , order
  );
  IWriteSupporter shortSupporter = ByteBufferSupporterFactory.createWriteSupporter(
      buffer , shortStart , shortLength , order
  );

  return new WriteSupporter3( byteSupporter , shortSupporter );
}
 
Example 4
Source File: Stat.java    From util with Apache License 2.0 6 votes vote down vote up
public static Stat lstat(String file) throws IOException {
    NativeBuffer nativeBuffer = new NativeBuffer(92, ByteOrder.nativeOrder());
    try {
        DirectMemory direct = nativeBuffer.memory();
        int err = lstat(file, direct.getAddress());
        if (err == errstr.indexOf("ENOENT")) {
            throw new FileNotFoundException("No such file or directory: "+file);
        }
        if (err != 0) {
            throw new IOException("stat on path "+file+" failed with error "+(err < 0 ? "unknown" : errstr.get(err)));
        }
        return new Stat(direct);
    } finally {
        nativeBuffer.close();
    }
}
 
Example 5
Source File: MphMap.java    From mph-table with Apache License 2.0 6 votes vote down vote up
private MphMap(final TableMeta<K, V> meta, final byte[] data, final byte[] offsets) {
    this.meta = meta;
    this.data = data;
    this.offsets = offsets;
    dataMemory = new HeapMemory(data, ByteOrder.nativeOrder());
    minKey = meta.getMinKey();
    maxKey = meta.getMaxKey();
    if (offsets != null) {
        if (TableConfig.OffsetStorage.SELECTED.equals(meta.getConfig().getOffsetStorage())) {
            select = new HintedBsearchSelect(new Rank9(new ByteArrayBitVector(offsets)));
            memory = null;
        } else {
            select = null;
            memory = new HeapMemory(offsets, ByteOrder.nativeOrder());
        }
    } else {
        select = null;
        memory = null;
    }
}
 
Example 6
Source File: NumberToBinaryUtils.java    From multiple-dimension-spread with Apache License 2.0 5 votes vote down vote up
@Override
public IWriteSupporter toWriteSuppoter( final int rows , final byte[] buffer , final int start , final int length ) throws IOException{
  ByteOrder order = ByteOrder.nativeOrder();
  byte byteOrderByte = order == ByteOrder.BIG_ENDIAN ? (byte)0 : (byte)1;

  buffer[start] = HEADER_8;
  buffer[start+1] = byteOrderByte;

  int longStart = start + HEADER_SIZE;
  int longLength = length - HEADER_SIZE;
  return ByteBufferSupporterFactory.createWriteSupporter( buffer , longStart , longLength , order );
}
 
Example 7
Source File: FrameDescriptor.java    From aeron with Apache License 2.0 5 votes vote down vote up
/**
 * Write the length header for a frame in a memory ordered fashion.
 *
 * @param buffer      containing the frame.
 * @param termOffset  at which a frame begins.
 * @param frameLength field to be set for the frame.
 */
public static void frameLengthOrdered(final UnsafeBuffer buffer, final int termOffset, final int frameLength)
{
    int length = frameLength;
    if (ByteOrder.nativeOrder() != LITTLE_ENDIAN)
    {
        length = Integer.reverseBytes(frameLength);
    }

    buffer.putIntOrdered(termOffset, length);
}
 
Example 8
Source File: SafeMemoryWriter.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public void writeShort(int val) throws IOException
{
    if (order != ByteOrder.nativeOrder())
        val = Short.reverseBytes((short) val);
    long newLength = ensureCapacity(2);
    buffer.setShort(length, (short) val);
    length = newLength;
}
 
Example 9
Source File: IndexSummary.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public void serialize(IndexSummary t, DataOutputPlus out, boolean withSamplingLevel) throws IOException
{
    out.writeInt(t.minIndexInterval);
    out.writeInt(t.offsetCount);
    out.writeLong(t.getOffHeapSize());
    if (withSamplingLevel)
    {
        out.writeInt(t.samplingLevel);
        out.writeInt(t.sizeAtFullSampling);
    }
    // our on-disk representation treats the offsets and the summary data as one contiguous structure,
    // in which the offsets are based from the start of the structure. i.e., if the offsets occupy
    // X bytes, the value of the first offset will be X. In memory we split the two regions up, so that
    // the summary values are indexed from zero, so we apply a correction to the offsets when de/serializing.
    // In this case adding X to each of the offsets.
    int baseOffset = t.offsetCount * 4;
    for (int i = 0 ; i < t.offsetCount ; i++)
    {
        int offset = t.offsets.getInt(i * 4) + baseOffset;
        // our serialization format for this file uses native byte order, so if this is different to the
        // default Java serialization order (BIG_ENDIAN) we have to reverse our bytes
        if (ByteOrder.nativeOrder() != ByteOrder.BIG_ENDIAN)
            offset = Integer.reverseBytes(offset);
        out.writeInt(offset);
    }
    out.write(t.entries, 0, t.entriesLength);
}
 
Example 10
Source File: NumberToBinaryUtils.java    From multiple-dimension-spread with Apache License 2.0 5 votes vote down vote up
@Override
public IWriteSupporter toWriteSuppoter( final int rows , final byte[] buffer , final int start , final int length ) throws IOException{
  ByteOrder order = ByteOrder.nativeOrder();
  byte byteOrderByte = order == ByteOrder.BIG_ENDIAN ? (byte)0 : (byte)1;

  buffer[start] = HEADER_0;
  buffer[start+1] = byteOrderByte;

  return new WriteSupporter_0();
}
 
Example 11
Source File: NumberToBinaryUtils.java    From multiple-dimension-spread with Apache License 2.0 5 votes vote down vote up
@Override
public IWriteSupporter toWriteSuppoter( final int rows , final byte[] buffer , final int start , final int length ) throws IOException{
  int shortLength = Short.BYTES * rows;

  ByteOrder order = ByteOrder.nativeOrder();
  byte byteOrderByte = order == ByteOrder.BIG_ENDIAN ? (byte)0 : (byte)1;

  buffer[start] = HEADER_2;
  buffer[start+1] = byteOrderByte;

  int shortStart = start + HEADER_SIZE;

  return new WriteSupporter_2( ByteBufferSupporterFactory.createWriteSupporter( buffer , shortStart , shortLength , order ) );
}
 
Example 12
Source File: ImageStream.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public ImageStream(int size) {
    this(size, ByteOrder.nativeOrder());
}
 
Example 13
Source File: CRC32C.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Updates the CRC-32C checksum reading from the specified address.
 */
@HotSpotIntrinsicCandidate
private static int updateDirectByteBuffer(int crc, long address,
                                          int off, int end) {

    // Do only byte reads for arrays so short they can't be aligned
    if (end - off >= 8) {

        // align on 8 bytes
        int alignLength = (8 - (int) ((address + off) & 0x7)) & 0x7;
        for (int alignEnd = off + alignLength; off < alignEnd; off++) {
            crc = (crc >>> 8)
                    ^ byteTable[(crc ^ UNSAFE.getByte(address + off)) & 0xFF];
        }

        if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN) {
            crc = Integer.reverseBytes(crc);
        }

        // slicing-by-8
        for (; off <= (end - Long.BYTES); off += Long.BYTES) {
            // Always reading two ints as reading a long followed by
            // shifting and casting was slower.
            int firstHalf = UNSAFE.getInt(address + off);
            int secondHalf = UNSAFE.getInt(address + off + Integer.BYTES);
            crc ^= firstHalf;
            if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) {
                crc = byteTable7[crc & 0xFF]
                        ^ byteTable6[(crc >>> 8) & 0xFF]
                        ^ byteTable5[(crc >>> 16) & 0xFF]
                        ^ byteTable4[crc >>> 24]
                        ^ byteTable3[secondHalf & 0xFF]
                        ^ byteTable2[(secondHalf >>> 8) & 0xFF]
                        ^ byteTable1[(secondHalf >>> 16) & 0xFF]
                        ^ byteTable0[secondHalf >>> 24];
            } else { // ByteOrder.BIG_ENDIAN
                crc = byteTable0[secondHalf & 0xFF]
                        ^ byteTable1[(secondHalf >>> 8) & 0xFF]
                        ^ byteTable2[(secondHalf >>> 16) & 0xFF]
                        ^ byteTable3[secondHalf >>> 24]
                        ^ byteTable4[crc & 0xFF]
                        ^ byteTable5[(crc >>> 8) & 0xFF]
                        ^ byteTable6[(crc >>> 16) & 0xFF]
                        ^ byteTable7[crc >>> 24];
            }
        }

        if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN) {
            crc = Integer.reverseBytes(crc);
        }
    }

    // Tail
    for (; off < end; off++) {
        crc = (crc >>> 8)
                ^ byteTable[(crc ^ UNSAFE.getByte(address + off)) & 0xFF];
    }

    return crc;
}
 
Example 14
Source File: MatFile.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
public void writeSubset(ECGDataSet[] data, int start, int end, int offset)
		throws IOException {
	int n = end-start;  //# of data points
	int m = data.length;	  	//# of channels

	//calculating matrix sizes
	int c = 56;
	int b = 40 + (8 + c)*n*2;
	int a = 48 + (8 + b)*m;

	ByteOrder ord = ByteOrder.nativeOrder();

	//descriptive text
	Date now = new Date();
	fs.write(pad("MATLAB 5.0 MAT-file, Created on: " + now.toString(),
				  116,
				  ' ').getBytes(), 
			 0, 
			 116);
	//flags? - not important
	fs.write(new byte[]{0, 0, 0, 0, 0, 0, 0, 0});
	//version - default
	fs.write(new byte[]{0, 1});
	//endian indicator - little
	fs.write("IM".getBytes());

	//////Start channel arrays (Cell Array)///////////
	//                                     miMATRIX
	fs.write(ByteBuffer.allocate(4).order(ord).putInt(14).array());
	//size of matrix in bytes
	fs.write(ByteBuffer.allocate(4).order(ord).putInt(a).array());
	
	//HEADER of channel arrays             miUINT32 
	fs.write(ByteBuffer.allocate(4).order(ord).putInt(6).array());
	fs.write(ByteBuffer.allocate(4).order(ord).putInt(8).array());
	//                         mxCELL_CLASS
	fs.write(new byte[]{1, 0, 0, 0, 0, 0, 0, 0});
	//                                     miINT32
	fs.write(ByteBuffer.allocate(4).order(ord).putInt(5).array());
	fs.write(ByteBuffer.allocate(4).order(ord).putInt(8).array());
	//write matrix size
	fs.write(ByteBuffer.allocate(4).order(ord).putInt(1).array());
	fs.write(ByteBuffer.allocate(4).order(ord).putInt(m).array());
	//name                                 miINT8
	fs.write(ByteBuffer.allocate(4).order(ord).putInt(1).array());
	fs.write(ByteBuffer.allocate(4).order(ord).putInt(5).array());
	fs.write("leads".getBytes());
	fs.write(new byte[]{0, 0, 0}); //padding
	//END HEADER

	for(int i = 0; i < m; i++) {
		//////////Start channel array (Double Array)////////
		//                                     miMATRIX
		fs.write(ByteBuffer.allocate(4).order(ord).putInt(14).array());
		//size of the matrix
		fs.write(ByteBuffer.allocate(4).order(ord).putInt(b).array());

		//HEADER of channel array
		fs.write(ByteBuffer.allocate(4).order(ord).putInt(6).array());
		fs.write(ByteBuffer.allocate(4).order(ord).putInt(8).array());
		fs.write(new byte[]{1, 0, 0, 0, 0, 0, 0, 0});
		//                                     miINT32
		fs.write(ByteBuffer.allocate(4).order(ord).putInt(5).array());
		fs.write(ByteBuffer.allocate(4).order(ord).putInt(8).array());
		//write matrix size
		fs.write(ByteBuffer.allocate(4).order(ord).putInt(2).array());
		fs.write(ByteBuffer.allocate(4).order(ord).putInt(n).array());
		//name                                 miINT8
		fs.write(ByteBuffer.allocate(4).order(ord).putInt(1).array());
		fs.write(ByteBuffer.allocate(4).order(ord).putInt(0).array()); //no name
		//END HEADER

		for(int j = 0; j < n; j++) {
			for(int k = 0; k < 2; k++) {
				fs.write(ByteBuffer.allocate(4).order(ord).putInt(14).array());
				fs.write(ByteBuffer.allocate(4).order(ord).putInt(c).array());

				fs.write(ByteBuffer.allocate(4).order(ord).putInt(6).array());
				fs.write(ByteBuffer.allocate(4).order(ord).putInt(8).array());
				fs.write(new byte[]{6, 0, 0, 0, 0, 0, 0, 0});

				fs.write(ByteBuffer.allocate(4).order(ord).putInt(5).array());
				fs.write(ByteBuffer.allocate(4).order(ord).putInt(8).array());
				fs.write(ByteBuffer.allocate(4).order(ord).putInt(1).array());
				fs.write(ByteBuffer.allocate(4).order(ord).putInt(1).array());

				fs.write(ByteBuffer.allocate(4).order(ord).putInt(1).array());
				fs.write(ByteBuffer.allocate(4).order(ord).putInt(0).array()); //no name
		
				fs.write(ByteBuffer.allocate(4).order(ord).putInt(9).array());
				fs.write(ByteBuffer.allocate(4).order(ord).putInt(8).array());
				fs.write(ByteBuffer.allocate(8).order(ord)
									 .putDouble(data[i].getAt(j)[k]).array());
			}
		}
	}

	fs.flush();
	fs.close();
	//END
}
 
Example 15
Source File: BufferCache.java    From conga with Apache License 2.0 4 votes vote down vote up
/**
 * Constructor with default buffer size
 */
public BufferCache() {
  this(DEFAULT_CACHE_CAPACITY, DEFAULT_BUFFER_CAPACITY, ByteOrder.nativeOrder());
}
 
Example 16
Source File: MotifDnDConstants.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * DragBSI.h:
 *
 * typedef struct {
 *    BYTE          byte_order;
 *    BYTE          protocol_version;
 *    CARD16        num_target_lists B16;
 *    CARD32        heap_offset B32;
 * } xmMotifTargetsPropertyRec;
 */
private static long[][] getTargetListTable(long motifWindow)
  throws XException {

    WindowPropertyGetter wpg = new WindowPropertyGetter(motifWindow,
                                                        XA_MOTIF_DRAG_TARGETS,
                                                        0, 100000L,
                                                        false,
                                                        XA_MOTIF_DRAG_TARGETS.getAtom());
    try {
        int status = wpg.execute(XErrorHandler.IgnoreBadWindowHandler.getInstance());

        if (status != XConstants.Success
            || wpg.getActualType() != XA_MOTIF_DRAG_TARGETS.getAtom()
            || wpg.getData() == 0) {

            return null;
        }

        long data = wpg.getData();

        if (unsafe.getByte(data + 1) != MOTIF_DND_PROTOCOL_VERSION) {
            return null;
        }

        boolean swapNeeded = unsafe.getByte(data + 0) != getByteOrderByte();

        short numTargetLists = unsafe.getShort(data + 2);

        if (swapNeeded) {
            numTargetLists = Swapper.swap(numTargetLists);
        }

        long[][] table = new long[numTargetLists][];
        ByteOrder byteOrder = ByteOrder.nativeOrder();
        if (swapNeeded) {
            byteOrder = (byteOrder == ByteOrder.LITTLE_ENDIAN) ?
                ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
        }

        long bufptr = data + 8;
        for (short i = 0; i < numTargetLists; i++) {
            short numTargets = unsafe.getShort(bufptr);
            bufptr += 2;
            if (swapNeeded) {
                numTargets = Swapper.swap(numTargets);
            }

            table[i] = new long[numTargets];

            for (short j = 0; j < numTargets; j++) {
                // NOTE: cannot use Unsafe.getInt(), since it crashes on
                // Solaris/Sparc if the address is not a multiple of 4.
                int target = 0;
                if (byteOrder == ByteOrder.LITTLE_ENDIAN) {
                    for (int idx = 0; idx < 4; idx++) {
                        target |= (unsafe.getByte(bufptr + idx) << 8*idx)
                            & (0xFF << 8*idx);
                    }
                } else {
                    for (int idx = 0; idx < 4; idx++) {
                        target |= (unsafe.getByte(bufptr + idx) << 8*(3-idx))
                            & (0xFF << 8*(3-idx));
                    }
                }
                // NOTE: don't need to swap, since we read it in the proper
                // order already.
                table[i][j] = target;
                bufptr += 4;
            }
        }
        return table;
    } finally {
        wpg.dispose();
    }
}
 
Example 17
Source File: ImageStream.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public ImageStream() {
    this(1024, ByteOrder.nativeOrder());
}
 
Example 18
Source File: MotifDnDConstants.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * DragBSI.h:
 *
 * typedef struct {
 *    BYTE          byte_order;
 *    BYTE          protocol_version;
 *    CARD16        num_target_lists B16;
 *    CARD32        heap_offset B32;
 * } xmMotifTargetsPropertyRec;
 */
private static long[][] getTargetListTable(long motifWindow)
  throws XException {

    WindowPropertyGetter wpg = new WindowPropertyGetter(motifWindow,
                                                        XA_MOTIF_DRAG_TARGETS,
                                                        0, 100000L,
                                                        false,
                                                        XA_MOTIF_DRAG_TARGETS.getAtom());
    try {
        int status = wpg.execute(XErrorHandler.IgnoreBadWindowHandler.getInstance());

        if (status != XConstants.Success
            || wpg.getActualType() != XA_MOTIF_DRAG_TARGETS.getAtom()
            || wpg.getData() == 0) {

            return null;
        }

        long data = wpg.getData();

        if (unsafe.getByte(data + 1) != MOTIF_DND_PROTOCOL_VERSION) {
            return null;
        }

        boolean swapNeeded = unsafe.getByte(data + 0) != getByteOrderByte();

        short numTargetLists = unsafe.getShort(data + 2);

        if (swapNeeded) {
            numTargetLists = Swapper.swap(numTargetLists);
        }

        long[][] table = new long[numTargetLists][];
        ByteOrder byteOrder = ByteOrder.nativeOrder();
        if (swapNeeded) {
            byteOrder = (byteOrder == ByteOrder.LITTLE_ENDIAN) ?
                ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
        }

        long bufptr = data + 8;
        for (short i = 0; i < numTargetLists; i++) {
            short numTargets = unsafe.getShort(bufptr);
            bufptr += 2;
            if (swapNeeded) {
                numTargets = Swapper.swap(numTargets);
            }

            table[i] = new long[numTargets];

            for (short j = 0; j < numTargets; j++) {
                // NOTE: cannot use Unsafe.getInt(), since it crashes on
                // Solaris/Sparc if the address is not a multiple of 4.
                int target = 0;
                if (byteOrder == ByteOrder.LITTLE_ENDIAN) {
                    for (int idx = 0; idx < 4; idx++) {
                        target |= (unsafe.getByte(bufptr + idx) << 8*idx)
                            & (0xFF << 8*idx);
                    }
                } else {
                    for (int idx = 0; idx < 4; idx++) {
                        target |= (unsafe.getByte(bufptr + idx) << 8*(3-idx))
                            & (0xFF << 8*(3-idx));
                    }
                }
                // NOTE: don't need to swap, since we read it in the proper
                // order already.
                table[i][j] = target;
                bufptr += 4;
            }
        }
        return table;
    } finally {
        wpg.dispose();
    }
}
 
Example 19
Source File: UnsafeRangeDumpDoubleColumnBinaryMaker.java    From multiple-dimension-spread with Apache License 2.0 4 votes vote down vote up
@Override
public ColumnBinary toBinary(final ColumnBinaryMakerConfig commonConfig , final ColumnBinaryMakerCustomConfigNode currentConfigNode , final IColumn column ) throws IOException{
  ColumnBinaryMakerConfig currentConfig = commonConfig;
  if( currentConfigNode != null ){
    currentConfig = currentConfigNode.getCurrentConfig();
  }
  byte[] parentsBinaryRaw = new byte[ Byte.BYTES + column.size() + ( column.size() * Double.BYTES ) ];
  ByteOrder order = ByteOrder.nativeOrder();

  IWriteSupporter nullSupporter = ByteBufferSupporterFactory.createWriteSupporter( parentsBinaryRaw , 0 , column.size() , order );
  IWriteSupporter doubleSupporter = ByteBufferSupporterFactory.createWriteSupporter( parentsBinaryRaw ,  Byte.BYTES + column.size() , column.size() * Double.BYTES , order );

  int rowCount = 0;
  boolean hasNull = false;
  Double min = Double.MAX_VALUE;
  Double max = Double.MIN_VALUE;
  for( int i = 0 ; i < column.size() ; i++ ){
    ICell cell = column.get(i);
    if( cell.getType() == ColumnType.NULL ){
      nullSupporter.putByte( (byte)1 );
      hasNull = true;
    }
    else{
      rowCount++;
      PrimitiveCell byteCell = (PrimitiveCell) cell;
      nullSupporter.putByte( (byte)0 );
      Double target = Double.valueOf( byteCell.getRow().getDouble() );
      doubleSupporter.putDouble( target );
      if( 0 < min.compareTo( target ) ){
        min = Double.valueOf( target );
      }
      if( max.compareTo( target ) < 0 ){
        max = Double.valueOf( target );
      }
    }
  }

  if( ! hasNull && min.equals( max ) ){
    return ConstantColumnBinaryMaker.createColumnBinary( new DoubleObj( min ) , column.getColumnName() , column.size() );
  }

  int rawLength;
  byte byteOrderByte = order == ByteOrder.BIG_ENDIAN ? (byte)0 : (byte)1;
  parentsBinaryRaw[column.size()] = byteOrderByte;

  byte[] compressBinaryRaw;
  if( hasNull ){
    rawLength =  parentsBinaryRaw.length - ( Double.BYTES * ( column.size() - rowCount ) );
    compressBinaryRaw = currentConfig.compressorClass.compress( parentsBinaryRaw , 0 , rawLength , DataType.NUMBER );
  }
  else{
    rawLength = Byte.BYTES + column.size() * Double.BYTES;
    compressBinaryRaw = currentConfig.compressorClass.compress( parentsBinaryRaw , column.size() , parentsBinaryRaw.length - column.size() , DataType.NUMBER );
  }
  byte[] binary = new byte[ HEADER_SIZE + compressBinaryRaw.length ];
  ByteBuffer wrapBuffer = ByteBuffer.wrap( binary );
  wrapBuffer.putDouble( min );
  wrapBuffer.putDouble( max );
  wrapBuffer.put( hasNull ? (byte)1 : (byte)0 );
  wrapBuffer.put( compressBinaryRaw );

  return new ColumnBinary( this.getClass().getName() , currentConfig.compressorClass.getClass().getName() , column.getColumnName() , ColumnType.DOUBLE , column.size() , rawLength , rowCount * Double.BYTES , -1 , binary , 0 , binary.length , null );
}
 
Example 20
Source File: RingBufferSupplier.java    From conga with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor with default thread factory
 * 
 * @param consumer handles queued buffers
 * @param capacity capacity of each buffer. Should be a multiple of cache line.
 * @param queueDepth number of slots in the circular buffer. Must be a power of 2.
 */
public RingBufferSupplier(BiConsumer<String, ByteBuffer> consumer, int capacity, int queueDepth) {
  this(consumer, capacity, ByteOrder.nativeOrder(), queueDepth, Executors.defaultThreadFactory());
}