public void write(ByteBuffer buffer) throws IOException { int len = buffer.remaining(); ByteBufferUtil.arrayCopy(buffer, buffer.position(), this.buffer, this.buffer.position(), len); this.buffer.position(this.buffer.position() + len); } }
public static int put(ByteBuffer src, ByteBuffer trg) { int length = Math.min(src.remaining(), trg.remaining()); arrayCopy(src, src.position(), trg, trg.position(), length); trg.position(trg.position() + length); src.position(src.position() + length); return length; }
public static int put(ByteBuffer src, ByteBuffer trg) { int length = Math.min(src.remaining(), trg.remaining()); arrayCopy(src, src.position(), trg, trg.position(), length); trg.position(trg.position() + length); src.position(src.position() + length); return length; }
public static int put(ByteBuffer src, ByteBuffer trg) { int length = Math.min(src.remaining(), trg.remaining()); arrayCopy(src, src.position(), trg, trg.position(), length); trg.position(trg.position() + length); src.position(src.position() + length); return length; }
public static int put(ByteBuffer src, ByteBuffer trg) { int length = Math.min(src.remaining(), trg.remaining()); arrayCopy(src, src.position(), trg, trg.position(), length); trg.position(trg.position() + length); src.position(src.position() + length); return length; }
public static int put(ByteBuffer src, ByteBuffer trg) { int length = Math.min(src.remaining(), trg.remaining()); arrayCopy(src, src.position(), trg, trg.position(), length); trg.position(trg.position() + length); src.position(src.position() + length); return length; }
@Override public final void readFully(byte[] bytes) throws IOException { ByteBufferUtil.arrayCopy(buffer, buffer.position() + position, bytes, 0, bytes.length); position += bytes.length; }
public void write(ByteBuffer buffer) { int len = buffer.remaining(); expand(len); ByteBufferUtil.arrayCopy(buffer, buffer.position(), buf, this.count, len); this.count += len; }
public static ByteBuffer build(boolean isStatic, ByteBuffer... buffers) { int totalLength = isStatic ? 2 : 0; for (ByteBuffer bb : buffers) totalLength += 2 + bb.remaining() + 1; ByteBuffer out = ByteBuffer.allocate(totalLength); if (isStatic) out.putShort((short)STATIC_MARKER); for (ByteBuffer bb : buffers) { ByteBufferUtil.writeShortLength(out, bb.remaining()); int toCopy = bb.remaining(); ByteBufferUtil.arrayCopy(bb, bb.position(), out, out.position(), toCopy); out.position(out.position() + toCopy); out.put((byte) 0); } out.flip(); return out; }
public static ByteBuffer build(boolean isStatic, ByteBuffer... buffers) { int totalLength = isStatic ? 2 : 0; for (ByteBuffer bb : buffers) totalLength += 2 + bb.remaining() + 1; ByteBuffer out = ByteBuffer.allocate(totalLength); if (isStatic) out.putShort((short)STATIC_MARKER); for (ByteBuffer bb : buffers) { ByteBufferUtil.writeShortLength(out, bb.remaining()); int toCopy = bb.remaining(); ByteBufferUtil.arrayCopy(bb, bb.position(), out, out.position(), toCopy); out.position(out.position() + toCopy); out.put((byte) 0); } out.flip(); return out; }
public static ByteBuffer build(boolean isStatic, ByteBuffer... buffers) { int totalLength = isStatic ? 2 : 0; for (ByteBuffer bb : buffers) totalLength += 2 + bb.remaining() + 1; ByteBuffer out = ByteBuffer.allocate(totalLength); if (isStatic) out.putShort((short)STATIC_MARKER); for (ByteBuffer bb : buffers) { ByteBufferUtil.writeShortLength(out, bb.remaining()); int toCopy = bb.remaining(); ByteBufferUtil.arrayCopy(bb, bb.position(), out, out.position(), toCopy); out.position(out.position() + toCopy); out.put((byte) 0); } out.flip(); return out; }
public static ByteBuffer build(boolean isStatic, ByteBuffer... buffers) { int totalLength = isStatic ? 2 : 0; for (ByteBuffer bb : buffers) totalLength += 2 + bb.remaining() + 1; ByteBuffer out = ByteBuffer.allocate(totalLength); if (isStatic) out.putShort((short)STATIC_MARKER); for (ByteBuffer bb : buffers) { ByteBufferUtil.writeShortLength(out, bb.remaining()); int toCopy = bb.remaining(); ByteBufferUtil.arrayCopy(bb, bb.position(), out, out.position(), toCopy); out.position(out.position() + toCopy); out.put((byte) 0); } out.flip(); return out; }
ByteBufferUtil.arrayCopy(context, context.position() + HEADER_SIZE_LENGTH, marked,
ByteBufferUtil.arrayCopy(context, context.position() + HEADER_SIZE_LENGTH, marked,
ByteBufferUtil.arrayCopy(context, context.position() + HEADER_SIZE_LENGTH, marked,
public synchronized void write(ByteBuffer buffer) throws IOException { int len = buffer.remaining(); if (len < 16) { int offset = buffer.position(); for (int i = 0 ; i < len ; i++) write(buffer.get(i + offset)); return; } byte[] buf = this.buf; if (buf == null) this.buf = buf = new byte[256]; int offset = 0; while (len > 0) { int sublen = Math.min(buf.length, len); ByteBufferUtil.arrayCopy(buffer, buffer.position() + offset, buf, 0, sublen); write(buf, 0, sublen); offset += sublen; len -= sublen; } }
@Override public int write(ByteBuffer src) throws IOException { int toWrite = src.remaining(); if (src.hasArray()) { outputStream.write(src.array(), src.arrayOffset() + src.position(), src.remaining()); src.position(src.limit()); return toWrite; } if (toWrite < 16) { int offset = src.position(); for (int i = 0 ; i < toWrite ; i++) outputStream.write(src.get(i + offset)); src.position(src.limit()); return toWrite; } byte[] buf = retrieveTemporaryBuffer(toWrite); int totalWritten = 0; while (totalWritten < toWrite) { int toWriteThisTime = Math.min(buf.length, toWrite - totalWritten); org.apache.cassandra.utils.ByteBufferUtil.arrayCopy(src, src.position() + totalWritten, buf, 0, toWriteThisTime); outputStream.write(buf, 0, toWriteThisTime); totalWritten += toWriteThisTime; } src.position(src.limit()); return totalWritten; }
@Override public int write(ByteBuffer src) throws IOException { int toWrite = src.remaining(); if (src.hasArray()) { DataOutputStreamPlus.this.write(src.array(), src.arrayOffset() + src.position(), src.remaining()); src.position(src.limit()); return toWrite; } if (toWrite < 16) { int offset = src.position(); for (int i = 0 ; i < toWrite ; i++) DataOutputStreamPlus.this.write(src.get(i + offset)); src.position(src.limit()); return toWrite; } byte[] buf = retrieveTemporaryBuffer(toWrite); int totalWritten = 0; while (totalWritten < toWrite) { int toWriteThisTime = Math.min(buf.length, toWrite - totalWritten); ByteBufferUtil.arrayCopy(src, src.position() + totalWritten, buf, 0, toWriteThisTime); DataOutputStreamPlus.this.write(buf, 0, toWriteThisTime); totalWritten += toWriteThisTime; } src.position(src.limit()); return totalWritten; }
public void update(ByteBuffer b, int off, int len) { if (b.hasArray()) { update(b.array(), b.arrayOffset() + off, len); } else if (len < 16) { doUpdate(b, off, len); } else { byte[] buf = BUFFER.get(); while (len > 0) { int l = Math.min(len, buf.length); ByteBufferUtil.arrayCopy(b, off, buf, 0, l); update(buf, 0, l); len -= l; off += l; } } }
private int writeAtMost(ByteBuffer data, int offset, int length) { if (current >= bufferOffset + buffer.length) reBuffer(); assert current < bufferOffset + buffer.length : String.format("File (%s) offset %d, buffer offset %d.", getPath(), current, bufferOffset); int toCopy = Math.min(length, buffer.length - bufferCursor()); // copy bytes from external buffer ByteBufferUtil.arrayCopy(data, offset, buffer, bufferCursor(), toCopy); assert current <= bufferOffset + buffer.length : String.format("File (%s) offset %d, buffer offset %d.", getPath(), current, bufferOffset); validBufferBytes = Math.max(validBufferBytes, bufferCursor() + toCopy); current += toCopy; return toCopy; }