Java Code Examples for java.nio.ByteBuffer.getLong()

The following are Jave code examples for showing how to use getLong() of the java.nio.ByteBuffer class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: sstore-soft   File: ExecutionEngineIPC.java   View Source Code Vote up 6 votes
@Override
public long tableHashCode(int tableId) {
    try {
        m_data.clear();
        m_data.putInt(Commands.TableHashCode.m_id);
        m_data.putInt(tableId);

        m_data.flip();
        m_connection.write();

        m_connection.readStatusByte();
        ByteBuffer hashCode = ByteBuffer.allocate(8);
        while (hashCode.hasRemaining()) {
            int read = m_connection.m_socketChannel.read(hashCode);
            if (read <= 0) {
                throw new EOFException();
            }
        }
        hashCode.flip();
        return hashCode.getLong();
    } catch (final IOException e) {
        System.out.println("Exception: " + e.getMessage());
        throw new RuntimeException(e);
    }
}
 
Example 2
Project: jchmlib   File: ChmItsfHeader.java   View Source Code Vote up 6 votes
public ChmItsfHeader(ByteBuffer bb) throws IOException {
    String signature = ByteBufferHelper.parseString(bb, 4, "ASCII");
    if (!signature.equals("ITSF")) {
        throw new IOException("Unexpected ITSF header signature.");
    }
    try {
        int version = bb.getInt();
        ByteBufferHelper.skip(bb, 12);
        langId = bb.getInt();
        ByteBufferHelper.skip(bb, 48);
        dirOffset = bb.getLong();
        long dirLen = bb.getLong();
        if (version >= 3) {
            dataOffset = bb.getLong();
        } else {
            dataOffset = dirOffset + dirLen;
        }
    } catch (Exception e) {
        throw new IOException("Failed to parse ITSF header", e);
    }
}
 
Example 3
Project: burstcoin   File: Attachment.java   View Source Code Vote up 6 votes
AdvancedPaymentEscrowCreation(ByteBuffer buffer, byte transactionVersion) throws NxtException.NotValidException {
	super(buffer, transactionVersion);
	this.amountNQT = buffer.getLong();
	this.deadline = buffer.getInt();
	this.deadlineAction = Escrow.byteToDecision(buffer.get());
	this.requiredSigners = buffer.get();
	byte totalSigners = buffer.get();
	if(totalSigners > 10 || totalSigners <= 0) {
		throw new NxtException.NotValidException("Invalid number of signers listed on create escrow transaction");
	}
	for(int i = 0; i < totalSigners; i++) {
		if(!this.signers.add(buffer.getLong())) {
			throw new NxtException.NotValidException("Duplicate signer on escrow creation");
		}
	}
}
 
Example 4
Project: fresco_floodlight   File: BSNPROBE.java   View Source Code Vote up 6 votes
@Override
public IPacket deserialize(byte[] data, int offset, int length)
        throws PacketParsingException {
    ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
    
    controllerId = bb.getLong();
    sequenceId = bb.getInt();
    bb.get(this.srcMac, 0, 6);
    bb.get(this.dstMac, 0, 6);
    this.srcSwDpid = bb.getLong();
    this.srcPortNo = bb.getInt();
    
    if (bb.hasRemaining()) {
    	this.payload = new Data();
     this.payload = payload.deserialize(data, bb.position(), bb.limit() - bb.position());
     this.payload.setParent(this);
    }
    
    return this;
}
 
Example 5
Project: MetadataEditor   File: Mp4MvhdBox.java   View Source Code Vote up 6 votes
/**
 * @param header     header info
 * @param dataBuffer data of box (doesnt include header data)
 */
public Mp4MvhdBox(Mp4BoxHeader header, ByteBuffer dataBuffer)
{
    this.header = header;
    dataBuffer.order(ByteOrder.BIG_ENDIAN);
    byte version = dataBuffer.get(VERSION_FLAG_POS);

    if (version == LONG_FORMAT)
    {
        timeScale = dataBuffer.getInt(TIMESCALE_LONG_POS);
        timeLength = dataBuffer.getLong(DURATION_LONG_POS);

    }
    else
    {
        timeScale = dataBuffer.getInt(TIMESCALE_SHORT_POS);
        timeLength = Utils.u(dataBuffer.getInt(DURATION_SHORT_POS));
    }
}
 
Example 6
Project: s-store   File: ExecutionEngineIPC.java   View Source Code Vote up 6 votes
@Override
public long tableHashCode(int tableId) {
    try {
        m_data.clear();
        m_data.putInt(Commands.TableHashCode.m_id);
        m_data.putInt(tableId);

        m_data.flip();
        m_connection.write();

        m_connection.readStatusByte();
        ByteBuffer hashCode = ByteBuffer.allocate(8);
        while (hashCode.hasRemaining()) {
            int read = m_connection.m_socketChannel.read(hashCode);
            if (read <= 0) {
                throw new EOFException();
            }
        }
        hashCode.flip();
        return hashCode.getLong();
    } catch (final IOException e) {
        System.out.println("Exception: " + e.getMessage());
        throw new RuntimeException(e);
    }
}
 
Example 7
Project: nn_nex_logging_and_research   File: ElfSymbol.java   View Source Code Vote up 6 votes
ElfSymbol(ElfReader reader, ElfStringTable strtab, int offset) {
    ByteBuffer buf = reader.buf;
    this.reader = reader;
    this.strtab = strtab;
    this.nameIndex = buf.getInt(offset);

    if (reader.elf64) {
        this.info = buf.get(offset + 4) & 0xff;
        this.other = buf.get(offset + 5);
        this.sectionIndex = buf.getShort(offset + 6) & 0xffff;
        this.value = buf.getLong(offset + 8);
        this.size = buf.getInt(offset + 16);
    } else {
        this.value = buf.getInt(offset + 4) & 0xffffffffL;
        this.size = buf.getInt(offset + 8) & 0xffffffffL;
        this.info = buf.get(offset + 12) & 0xff;
        this.other = buf.get(offset + 13);
        this.sectionIndex = buf.getShort(offset + 14) & 0xffff;
    }
}
 
Example 8
Project: ditb   File: HFileBlock.java   View Source Code Vote up 6 votes
/**
 * Creates a block from an existing buffer starting with a header. Rewinds
 * and takes ownership of the buffer. By definition of rewind, ignores the
 * buffer position, but if you slice the buffer beforehand, it will rewind
 * to that point. The reason this has a minorNumber and not a majorNumber is
 * because majorNumbers indicate the format of a HFile whereas minorNumbers
 * indicate the format inside a HFileBlock.
 */
HFileBlock(ByteBuffer b, boolean usesHBaseChecksum) throws IOException {
  b.rewind();
  blockType = BlockType.read(b);
  onDiskSizeWithoutHeader = b.getInt(Header.ON_DISK_SIZE_WITHOUT_HEADER_INDEX);
  uncompressedSizeWithoutHeader = b.getInt(Header.UNCOMPRESSED_SIZE_WITHOUT_HEADER_INDEX);
  prevBlockOffset = b.getLong(Header.PREV_BLOCK_OFFSET_INDEX);
  HFileContextBuilder contextBuilder = new HFileContextBuilder();
  contextBuilder.withHBaseCheckSum(usesHBaseChecksum);
  if (usesHBaseChecksum) {
    contextBuilder.withChecksumType(ChecksumType.codeToType(b.get(Header.CHECKSUM_TYPE_INDEX)));
    contextBuilder.withBytesPerCheckSum(b.getInt(Header.BYTES_PER_CHECKSUM_INDEX));
    this.onDiskDataSizeWithHeader = b.getInt(Header.ON_DISK_DATA_SIZE_WITH_HEADER_INDEX);
  } else {
    contextBuilder.withChecksumType(ChecksumType.NULL);
    contextBuilder.withBytesPerCheckSum(0);
    this.onDiskDataSizeWithHeader = onDiskSizeWithoutHeader +
                                     HConstants.HFILEBLOCK_HEADER_SIZE_NO_CHECKSUM;
  }
  this.fileContext = contextBuilder.build();
  buf = b;
  buf.rewind();
}
 
Example 9
Project: nn_nex_logging_and_research   File: ElfSection.java   View Source Code Vote up 6 votes
ElfSection(ElfReader reader, int offset) {
    ByteBuffer buf = reader.buf;
    this.reader = reader;
    this.nameIndex = buf.getInt(offset);
    this.type = buf.getInt(offset + 4);

    if (reader.elf64) {
        this.flags = buf.getLong(offset + 8);
        this.address = buf.getLong(offset + 16);
        this.offset = buf.getLong(offset + 24);
        this.size = buf.getLong(offset + 32);
        this.linkIndex = buf.getInt(offset + 40);
        this.info = buf.getInt(offset + 44);
        this.align = buf.getLong(offset + 48);
        this.entrySize = buf.getLong(offset + 56);
    } else {
        this.flags = buf.getInt(offset + 8) & 0xffffffffL;
        this.address = buf.getInt(offset + 12) & 0xffffffffL;
        this.offset = buf.getInt(offset + 16) & 0xffffffffL;
        this.size = buf.getInt(offset + 20) & 0xffffffffL;
        this.linkIndex = buf.getInt(offset + 24);
        this.info = buf.getInt(offset + 28);
        this.align = buf.getInt(offset + 32);
        this.entrySize = buf.getInt(offset + 36);
    }
}
 
Example 10
Project: multiple-dimension-spread   File: OptimizeDumpLongColumnBinaryMaker.java   View Source Code Vote up 5 votes
@Override
public PrimitiveObject[] getPrimitiveArray( final byte[] buffer , final int start , final int length ) throws IOException{
  int size = length / Long.BYTES;
  PrimitiveObject[] result = new PrimitiveObject[size];
  ByteBuffer wrapBuffer = ByteBuffer.wrap( buffer , start , length );
  for( int i = 0 ; i < size ; i++ ){
    result[i] = new LongObj( wrapBuffer.getLong() );
  }
  return result;
}
 
Example 11
Project: burstcoin   File: AT_API_Helper.java   View Source Code Vote up 5 votes
public static long getLong(byte[] b){
	ByteBuffer buffer = ByteBuffer.allocate(8);
	buffer.order(ByteOrder.LITTLE_ENDIAN);
	buffer.position(0);
	buffer.put(b);
	return buffer.getLong(0);
}
 
Example 12
Project: openjdk-jdk10   File: ByteBufferTest.java   View Source Code Vote up 5 votes
Ret unalignedReadSnippet(byte[] arg) {
    ByteBuffer buffer = ByteBuffer.wrap(arg).order(byteOrder);

    Ret ret = new Ret();
    ret.byteValue = buffer.get();
    ret.shortValue = buffer.getShort();
    ret.intValue = buffer.getInt();
    ret.longValue = buffer.getLong();
    ret.doubleValue = buffer.getDouble();
    ret.floatValue = buffer.getFloat();

    return ret;
}
 
Example 13
Project: openjdk-jdk10   File: DirectByteBufferTest.java   View Source Code Vote up 5 votes
Ret alignedReadSnippet(byte[] arg) {
    ByteBuffer buffer = makeDirect(arg, byteOrder);

    Ret ret = new Ret();
    ret.byteValue = buffer.get();
    ret.byteValue += buffer.get();
    ret.shortValue = buffer.getShort();
    ret.intValue = buffer.getInt();
    ret.longValue = buffer.getLong();
    ret.doubleValue = buffer.getDouble();
    ret.floatValue = buffer.getFloat();

    return ret;
}
 
Example 14
Project: EasyDiameter   File: Integer64AVP.java   View Source Code Vote up 4 votes
@Override
public void decodeData(ByteBuffer buffer, int length) {
	data = buffer.getLong();
	addDataLength(length);
}
 
Example 15
Project: happylifeplat-transaction   File: TransactionXid.java   View Source Code Vote up 4 votes
public static UUID byteArrayToUUID(byte[] bytes) {
    ByteBuffer bb = ByteBuffer.wrap(bytes);
    long firstLong = bb.getLong();
    long secondLong = bb.getLong();
    return new UUID(firstLong, secondLong);
}
 
Example 16
Project: gitplex-mit   File: AbstractEnvironmentManager.java   View Source Code Vote up 4 votes
protected long bytesToLong(byte[] bytes) {
    ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);
    buffer.put(bytes);
    buffer.flip(); 
    return buffer.getLong();
}
 
Example 17
Project: burstcoin   File: Attachment.java   View Source Code Vote up 4 votes
DigitalGoodsFeedback(ByteBuffer buffer, byte transactionVersion) {
    super(buffer, transactionVersion);
    this.purchaseId = buffer.getLong();
}
 
Example 18
Project: https-github.com-apache-zookeeper   File: TraceFormatter.java   View Source Code Vote up 4 votes
/**
 * @param args
 * @throws IOException
 */
public static void main(String[] args) throws IOException {
    if (args.length != 1) {
        System.err.println("USAGE: TraceFormatter trace_file");
        System.exit(2);
    }
    FileChannel fc = new FileInputStream(args[0]).getChannel();
    while (true) {
        ByteBuffer bb = ByteBuffer.allocate(41);
        fc.read(bb);
        bb.flip();

        byte app = bb.get();
        long time = bb.getLong();
        long id = bb.getLong();
        int cxid = bb.getInt();
        long zxid = bb.getLong();
        int txnType = bb.getInt();
        int type = bb.getInt();
        int len = bb.getInt();
        bb = ByteBuffer.allocate(len);
        fc.read(bb);
        bb.flip();
        String path = "n/a";
        if (bb.remaining() > 0) {
            if (type != OpCode.createSession) {
                int pathLen = bb.getInt();
                byte b[] = new byte[pathLen];
                bb.get(b);
                path = new String(b);
            }
        }
        System.out.println(DateFormat.getDateTimeInstance(DateFormat.SHORT,
                DateFormat.LONG).format(new Date(time))
                + ": "
                + (char) app
                + " id=0x"
                + Long.toHexString(id)
                + " cxid="
                + cxid
                + " op="
                + op2String(type)
                + " zxid=0x"
                + Long.toHexString(zxid)
                + " txnType="
                + txnType
                + " len="
                + len + " path=" + path);
    }
}
 
Example 19
Project: burstcoin   File: Attachment.java   View Source Code Vote up 4 votes
private ColoredCoinsOrderPlacement(ByteBuffer buffer, byte transactionVersion) {
    super(buffer, transactionVersion);
    this.assetId = buffer.getLong();
    this.quantityQNT = buffer.getLong();
    this.priceNQT = buffer.getLong();
}
 
Example 20
Project: mdict-parser-java   File: mdict.java   View Source Code Vote up 4 votes
private long _read_number(ByteBuffer sf) {
   	if(_number_width==4)
   		return sf.getInt();
   	else
   		return sf.getLong();
}