Пример #1
0
 @Override
 public void write(byte[] buffer, int offset, int length) throws IOException {
   mClosedHelper.throwIfClosed();
   if (length > 0) {
     try {
       synchronized (Framer.this) {
         writeIntFrame(mPrefix, length);
         writeBlob(buffer, offset, length);
         mMultiplexedOutputStream.flush();
       }
     } catch (IOException e) {
       // I/O error here can indicate the pipe is broken, so we need to prevent any
       // further writes.
       throw new DumpappOutputBrokenException(e);
     }
   }
 }
Пример #2
0
    @Override
    public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException {
      mClosedHelper.throwIfClosed();

      synchronized (Framer.this) {
        // Ask the client for more data...
        writeIntFrame(STDIN_REQUEST_FRAME_PREFIX, byteCount);
        byte b = readFrameType();
        if (b != STDIN_FRAME_PREFIX) {
          throw new UnexpectedFrameException(STDIN_FRAME_PREFIX, b);
        }

        // Read what they gave us...
        int length = readInt();
        if (length > 0) {
          if (length > byteCount) {
            throw new DumpappFramingException(
                "Expected at most " + byteCount + " bytes, got: " + length);
          }
          mInput.readFully(buffer, byteOffset, length);
        }
        return length;
      }
    }
Пример #3
0
 @Override
 public void close() throws IOException {
   mClosedHelper.close();
 }