@Override public void write(Buffer source, long byteCount) throws IOException { long toRead = Math.min(remainingByteCount, byteCount); if (toRead > 0) { source.read(buffer, toRead); } long toSkip = byteCount - toRead; if (toSkip > 0) { source.skip(toSkip); } remainingByteCount -= toRead; receivedByteCount += byteCount; }
private static void skipName(Buffer in) throws EOFException { // 0 - 63 bytes int length = in.readByte(); if (length < 0) { // compressed name pointer, first two bits are 1 // drop second byte of compression offset in.skip(1); } else { while (length > 0) { // skip each part of the domain name in.skip(length); length = in.readByte(); } } } }
@Override public void write(Buffer source, long byteCount) throws IOException { if (hasErrors) { source.skip(byteCount); return; } try { super.write(source, byteCount); } catch (IOException e) { hasErrors = true; onException(e); } }
/** * Advances the position until after the next newline character. If the line * is terminated by "\r\n", the '\n' must be consumed as whitespace by the * caller. */ private void skipToEndOfLine() throws IOException { long index = source.indexOfElement(LINEFEED_OR_CARRIAGE_RETURN); buffer.skip(index != -1 ? index + 1 : buffer.size()); }
private void skipQuotedValue(ByteString runTerminator) throws IOException { while (true) { long index = source.indexOfElement(runTerminator); if (index == -1L) throw syntaxError("Unterminated string"); if (buffer.getByte(index) == '\\') { buffer.skip(index + 1); readEscapeCharacter(); } else { buffer.skip(index + 1); return; } } }
private void skipUnquotedValue() throws IOException { long i = source.indexOfElement(UNQUOTED_STRING_TERMINALS); buffer.skip(i != -1L ? i : buffer.size()); }
@Override public void write(Buffer source, long byteCount) throws IOException { if (!channel.isOpen()) throw new IllegalStateException("closed"); if (byteCount == 0) return; long remaining = byteCount; while (remaining > 0) { timeout.throwIfReached(); try (Buffer.UnsafeCursor ignored = source.readUnsafe(cursor)) { cursor.seek(0); int length = (int) Math.min(cursor.end - cursor.start, remaining); int written = channel.write(ByteBuffer.wrap(cursor.data, cursor.start, length)); remaining -= written; source.skip(written); } } }
@Override public void write(Buffer source, long byteCount) throws IOException { if (hasErrors) { source.skip(byteCount); return; } try { super.write(source, byteCount); } catch (IOException e) { hasErrors = true; onException(e); } }
private void completeEvent(String id, String type, Buffer data) throws IOException { skipCrAndOrLf(); if (data.size() != 0L) { lastId = id; data.skip(1L); // Leading newline. callback.onEvent(id, type, data.readUtf8()); } }
/** * Advances the position until after the next newline character. If the line * is terminated by "\r\n", the '\n' must be consumed as whitespace by the * caller. */ private void skipToEndOfLine() throws IOException { long index = source.indexOfElement(LINEFEED_OR_CARRIAGE_RETURN); buffer.skip(index != -1 ? index + 1 : buffer.size()); }
private void skipQuotedValue(ByteString runTerminator) throws IOException { while (true) { long index = source.indexOfElement(runTerminator); if (index == -1L) throw syntaxError("Unterminated string"); if (buffer.getByte(index) == '\\') { buffer.skip(index + 1); readEscapeCharacter(); } else { buffer.skip(index + 1); return; } } }
private void skipUnquotedValue() throws IOException { long i = source.indexOfElement(UNQUOTED_STRING_TERMINALS); buffer.skip(i != -1L ? i : buffer.size()); }
@Override public void write(Buffer source, long byteCount) throws IOException { log.add("write(" + source + ", " + byteCount + ")"); source.skip(byteCount); throwIfScheduled(); }
/** * Skips through the next closing block comment. */ private boolean skipToEndOfBlockComment() throws IOException { long index = source.indexOf(CLOSING_BLOCK_COMMENT); boolean found = index != -1; buffer.skip(found ? index + CLOSING_BLOCK_COMMENT.size() : buffer.size()); return found; }
result.add(InetAddress.getByAddress(bytes)); } else { buf.skip(length);
buffer.skip(buffer.size() - bufferMaxSize);
@Test public void inflateIntoNonemptySink() throws Exception { for (int i = 0; i < SEGMENT_SIZE; i++) { Buffer inflated = new Buffer().writeUtf8(repeat('a', i)); Buffer deflated = decodeBase64( "eJxzz09RyEjNKVAoLdZRKE9VL0pVyMxTKMlIVchIzEspVshPU0jNS8/MS00tKtYDAF6CD5s="); InflaterSource source = new InflaterSource(deflated, new Inflater()); while (source.read(inflated, Integer.MAX_VALUE) != -1) { } inflated.skip(i); assertEquals("God help us, we're in the hands of engineers.", inflated.readUtf8()); } }
@Test public void deflateIntoNonemptySink() throws Exception { String original = "They're moving in herds. They do move in herds."; // Exercise all possible offsets for the outgoing segment. for (int i = 0; i < SEGMENT_SIZE; i++) { Buffer data = new Buffer().writeUtf8(original); Buffer sink = new Buffer().writeUtf8(repeat('a', i)); DeflaterSink deflaterSink = new DeflaterSink(sink, new Deflater()); deflaterSink.write(data, data.size()); deflaterSink.close(); sink.skip(i); Buffer inflated = inflate(sink); assertEquals(original, inflated.readUtf8()); } }
@Test public void writeToSpanningSegments() throws Exception { Buffer buffer = new Buffer(); buffer.writeUtf8(repeat('a', SEGMENT_SIZE * 2)); buffer.writeUtf8(repeat('b', SEGMENT_SIZE * 2)); ByteArrayOutputStream out = new ByteArrayOutputStream(); buffer.skip(10); buffer.writeTo(out, SEGMENT_SIZE * 3); assertEquals(repeat('a', SEGMENT_SIZE * 2 - 10) + repeat('b', SEGMENT_SIZE + 10), out.toString()); assertEquals(repeat('b', SEGMENT_SIZE - 10), buffer.readUtf8(buffer.size())); }
@Test public void readFromPrefixOfBuffer() throws Exception { source.writeUtf8("z"); source.write(r32k); source.skip(1); source.writeUtf8(TestUtil.repeat('z', SEGMENT_SIZE * 2 - 1)); HashingSink hashingSink = HashingSink.sha256(sink); hashingSink.write(source, r32k.size()); assertEquals(SHA256_r32k, hashingSink.hash()); } }