private void readTheList() throws IOException { byte[] publicSuffixListBytes; byte[] publicSuffixExceptionListBytes; InputStream resource = PublicSuffixDatabase.class.getResourceAsStream(PUBLIC_SUFFIX_RESOURCE); if (resource == null) return; try (BufferedSource bufferedSource = Okio.buffer(new GzipSource(Okio.source(resource)))) { int totalBytes = bufferedSource.readInt(); publicSuffixListBytes = new byte[totalBytes]; bufferedSource.readFully(publicSuffixListBytes); int totalExceptionBytes = bufferedSource.readInt(); publicSuffixExceptionListBytes = new byte[totalExceptionBytes]; bufferedSource.readFully(publicSuffixExceptionListBytes); } synchronized (this) { this.publicSuffixListBytes = publicSuffixListBytes; this.publicSuffixExceptionListBytes = publicSuffixExceptionListBytes; } readCompleteLatch.countDown(); }
public EhTagDatabase(String name, BufferedSource source) throws IOException { this.name = name; int totalBytes = source.readInt(); tags = new byte[totalBytes]; source.readFully(tags); }
@Nullable private static byte[] getFileContent(File file, int length) { try (BufferedSource source = Okio.buffer(Okio.source(file))) { byte[] content = new byte[length]; source.readFully(content); return content; } catch (IOException e) { return null; } }
private void parseData(Buffer data, long end) throws IOException { data.writeByte('\n'); end -= skipNameAndDivider(4L); source.readFully(data, end); skipCrAndOrLf(); }
private void readTheList() throws IOException { byte[] publicSuffixListBytes; byte[] publicSuffixExceptionListBytes; InputStream resource = PublicSuffixDatabase.class.getResourceAsStream(PUBLIC_SUFFIX_RESOURCE); if (resource == null) return; try (BufferedSource bufferedSource = Okio.buffer(new GzipSource(Okio.source(resource)))) { int totalBytes = bufferedSource.readInt(); publicSuffixListBytes = new byte[totalBytes]; bufferedSource.readFully(publicSuffixListBytes); int totalExceptionBytes = bufferedSource.readInt(); publicSuffixExceptionListBytes = new byte[totalExceptionBytes]; bufferedSource.readFully(publicSuffixExceptionListBytes); } synchronized (this) { this.publicSuffixListBytes = publicSuffixListBytes; this.publicSuffixExceptionListBytes = publicSuffixExceptionListBytes; } readCompleteLatch.countDown(); }
/** * Reads a message body into across one or more frames. Control frames that occur between * fragments will be processed. If the message payload is masked this will unmask as it's being * processed. */ private void readMessage() throws IOException { while (true) { if (closed) throw new IOException("closed"); if (frameLength > 0) { source.readFully(messageFrameBuffer, frameLength); if (!isClient) { messageFrameBuffer.readAndWriteUnsafe(maskCursor); maskCursor.seek(messageFrameBuffer.size() - frameLength); toggleMask(maskCursor, maskKey); maskCursor.close(); } } if (isFinalFrame) break; // We are exhausted and have no continuations. readUntilNonControlFrame(); if (opcode != OPCODE_CONTINUATION) { throw new ProtocolException("Expected continuation opcode. Got: " + toHexString(opcode)); } } } }
/** * Reads a message body into across one or more frames. Control frames that occur between * fragments will be processed. If the message payload is masked this will unmask as it's being * processed. */ private void readMessage() throws IOException { while (true) { if (closed) throw new IOException("closed"); if (frameLength > 0) { source.readFully(messageFrameBuffer, frameLength); if (!isClient) { messageFrameBuffer.readAndWriteUnsafe(maskCursor); maskCursor.seek(messageFrameBuffer.size() - frameLength); toggleMask(maskCursor, maskKey); maskCursor.close(); } } if (isFinalFrame) break; // We are exhausted and have no continuations. readUntilNonControlFrame(); if (opcode != OPCODE_CONTINUATION) { throw new ProtocolException("Expected continuation opcode. Got: " + toHexString(opcode)); } } } }
@Test public void readFullyTooShortThrows() throws IOException { sink.writeUtf8("Hi"); sink.emit(); Buffer sink = new Buffer(); try { source.readFully(sink, 5); fail(); } catch (EOFException ignored) { } // Verify we read all that we could from the source. assertEquals("Hi", sink.readUtf8()); }
source.readFully(maskKey);
@Test public void readFullyByteArrayTooShortThrows() throws IOException { sink.writeUtf8("Hello"); sink.emit(); byte[] array = new byte[6]; try { source.readFully(array); fail(); } catch (EOFException ignored) { } // Verify we read all that we could from the source. assertByteArraysEquals(new byte[] { 'H', 'e', 'l', 'l', 'o', 0 }, array); }
private void readControlFrame() throws IOException { if (frameLength > 0) { source.readFully(controlFrameBuffer, frameLength);
@Test public void readFully() throws Exception { sink.writeUtf8(repeat('a', 10000)); sink.emit(); Buffer sink = new Buffer(); source.readFully(sink, 9999); assertEquals(repeat('a', 9999), sink.readUtf8()); assertEquals("a", source.readUtf8()); }
@Test public void readFullyByteArray() throws IOException { Buffer data = new Buffer(); data.writeUtf8("Hello").writeUtf8(repeat('e', SEGMENT_SIZE)); byte[] expected = data.clone().readByteArray(); sink.write(data, data.size()); sink.emit(); byte[] sink = new byte[SEGMENT_SIZE + 5]; source.readFully(sink); assertByteArraysEquals(expected, sink); }
source.readFully(maskKey);
private void readControlFrame() throws IOException { if (frameLength > 0) { source.readFully(controlFrameBuffer, frameLength);
private void readTheList() throws IOException { byte[] publicSuffixListBytes; byte[] publicSuffixExceptionListBytes; InputStream resource = PublicSuffixDatabase.class.getResourceAsStream(PUBLIC_SUFFIX_RESOURCE); if (resource == null) return; BufferedSource bufferedSource = Okio.buffer(new GzipSource(Okio.source(resource))); try { int totalBytes = bufferedSource.readInt(); publicSuffixListBytes = new byte[totalBytes]; bufferedSource.readFully(publicSuffixListBytes); int totalExceptionBytes = bufferedSource.readInt(); publicSuffixExceptionListBytes = new byte[totalExceptionBytes]; bufferedSource.readFully(publicSuffixExceptionListBytes); } finally { closeQuietly(bufferedSource); } synchronized (this) { this.publicSuffixListBytes = publicSuffixListBytes; this.publicSuffixExceptionListBytes = publicSuffixExceptionListBytes; } readCompleteLatch.countDown(); }
private void readTheList() throws IOException { byte[] publicSuffixListBytes; byte[] publicSuffixExceptionListBytes; InputStream resource = PublicSuffixDatabase.class.getResourceAsStream(PUBLIC_SUFFIX_RESOURCE); if (resource == null) return; BufferedSource bufferedSource = Okio.buffer(new GzipSource(Okio.source(resource))); try { int totalBytes = bufferedSource.readInt(); publicSuffixListBytes = new byte[totalBytes]; bufferedSource.readFully(publicSuffixListBytes); int totalExceptionBytes = bufferedSource.readInt(); publicSuffixExceptionListBytes = new byte[totalExceptionBytes]; bufferedSource.readFully(publicSuffixExceptionListBytes); } finally { closeQuietly(bufferedSource); } synchronized (this) { this.publicSuffixListBytes = publicSuffixListBytes; this.publicSuffixExceptionListBytes = publicSuffixExceptionListBytes; } readCompleteLatch.countDown(); }
private void parseData(Buffer data, long end) throws IOException { data.writeByte('\n'); end -= skipNameAndDivider(4L); source.readFully(data, end); skipCrAndOrLf(); }
/** * Reads a message body into across one or more frames. Control frames that occur between * fragments will be processed. If the message payload is masked this will unmask as it's being * processed. */ private void readMessage() throws IOException { while (true) { if (closed) throw new IOException("closed"); if (frameLength > 0) { source.readFully(messageFrameBuffer, frameLength); if (!isClient) { messageFrameBuffer.readAndWriteUnsafe(maskCursor); maskCursor.seek(messageFrameBuffer.size() - frameLength); toggleMask(maskCursor, maskKey); maskCursor.close(); } } if (isFinalFrame) break; // We are exhausted and have no continuations. readUntilNonControlFrame(); if (opcode != OPCODE_CONTINUATION) { throw new ProtocolException("Expected continuation opcode. Got: " + toHexString(opcode)); } } } }
source.readFully(maskKey);