@Override public ByteBuffer getNext(ByteBuffer byteBuffer) { ByteBufferOutputStream next = new ByteBufferOutputStream(); try { next.write(byteBuffer); next.write((byte) 0); return next.getByteBuffer(); } finally { try { next.close(); } catch (Throwable t) { } } } }
@Override public void write(int b) { ByteBuffer buffer = getBufferWithCapacity(1); buffer.put((byte) b); }
public ByteBufferOutputStream() { reset(); }
ByteBufferOutputStream out = new ByteBufferOutputStream(); a = (byte) Character.toUpperCase((char) a); out.writeShort((short) (0x8000 | a)); out.writeShort((short) comparator.length()); out.write(ByteBufferUtil.bytes(comparator)); out.writeShort((short) cb.remaining()); out.write(cb.slice()); out.write(c.getEquality().toByte()); i++; serialized = out.getByteBuffer(); return serialized.duplicate();
@Override public ByteBuffer serialize() throws Exception { if (mutationMap.isEmpty()) { throw new Exception("Mutation is empty"); } ByteBufferOutputStream out = new ByteBufferOutputStream(); TIOStreamTransport transport = new TIOStreamTransport(out); batch_mutate_args args = new batch_mutate_args(); args.setMutation_map(mutationMap); try { args.write(new TBinaryProtocol(transport)); } catch (TException e) { throw ThriftConverter.ToConnectionPoolException(e); } return out.getByteBuffer(); }
@Override public ByteBuffer getEnd() { return end.getByteBuffer(); }
public void append(ByteBufferOutputStream out, Object value, Equality equality) { ComponentSerializer<?> serializer = components.get(position); // First, serialize the ByteBuffer for this component ByteBuffer cb; try { cb = serializer.serializeValue(value); } catch (Exception e) { throw new RuntimeException(e); } if (cb == null) { cb = EMPTY_BYTE_BUFFER; } // Write the data: <length><data><0> out.writeShort((short) cb.remaining()); out.write(cb.slice()); out.write(equality.toByte()); } };
/** Add a buffer to the output without copying, if possible. */ public void write(ByteBuffer buffer) { if (buffer.remaining() < bufferSize) { write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining()); } else { // append w/o copying bytes ByteBuffer dup = buffer.duplicate(); dup.position(buffer.limit()); // ready for flip buffers.add(dup); } } }
public ByteBuffer getByteBuffer() { List<ByteBuffer> list = getBufferList(); // if there's just one bytebuffer in list, return it if (list.size() == 1) { return list.get(0); } int size = 0; for (ByteBuffer buffer : list) { size += buffer.remaining(); } ByteBuffer result = ByteBuffer.allocate(size); for (ByteBuffer buffer : list) { result.put(buffer); } return (ByteBuffer) result.rewind(); }
@Override public ByteBuffer serialize() throws Exception { if (mutationMap.isEmpty()) { throw new Exception("Mutation is empty"); } ByteBufferOutputStream out = new ByteBufferOutputStream(); TIOStreamTransport transport = new TIOStreamTransport(out); batch_mutate_args args = new batch_mutate_args(); args.setMutation_map(mutationMap); try { args.write(new TBinaryProtocol(transport)); } catch (TException e) { throw ThriftConverter.ToConnectionPoolException(e); } return out.getByteBuffer(); }
@Override public ByteBuffer getStart() { return start.getByteBuffer(); }
@Override @Deprecated public ByteBuffer getStart() { return start.getByteBuffer(); }
public void writeChar(char value) { ByteBuffer buffer = getBufferWithCapacity(2); buffer.putChar(value); }
/** Returns all data written and resets the stream to be empty. */ public List<ByteBuffer> getBufferList() { List<ByteBuffer> result = buffers; reset(); for (ByteBuffer buffer : result) { buffer.flip(); } return result; }
@Override @Deprecated public ByteBuffer getEnd() { return end.getByteBuffer(); }
public void writeInt(int value) { ByteBuffer buffer = getBufferWithCapacity(4); buffer.putInt(value); }
public void writeFloat(float value) { ByteBuffer buffer = getBufferWithCapacity(4); buffer.putFloat(value); }
public void writeLong(long value) { ByteBuffer buffer = getBufferWithCapacity(8); buffer.putLong(value); }
public void writeDouble(double value) { ByteBuffer buffer = getBufferWithCapacity(8); buffer.putDouble(value); }
public void writeShort(short value) { ByteBuffer buffer = getBufferWithCapacity(2); buffer.putShort(value); }