Package org.chromium.sdk.util

Examples of org.chromium.sdk.util.ByteToCharConverter


    public LoggableInputStream wrapInputStream(final LoggableInputStream loggableReader,
        final StreamListener listener) {
      final InputStream originalInputStream = loggableReader.getInputStream();

      final InputStream wrappedInputStream = new InputStream() {
        private final ByteToCharConverter byteToCharConverter = new ByteToCharConverter(charset);
        @Override
        public int read() throws IOException {
          byte[] buffer = new byte[1];
          int res = readImpl(buffer, 0, 1);
          if (res <= 0) {
            return -1;
          } else {
            return buffer[0];
          }
        }

        @Override
        public int read(byte[] b, int off, int len) throws IOException {
          return readImpl(b, off, len);
        }

        private int readImpl(byte[] buf, int off, int len) throws IOException {
          int res = originalInputStream.read(buf, off, len);
          if (res > 0) {
            CharBuffer charBuffer = byteToCharConverter.convert(ByteBuffer.wrap(buf, off, res));
            listener.addContent(charBuffer);
          }
          return res;
        }
      };
View Full Code Here


      if (listener == null) {
        return originalLoggableWriter;
      }
      final OutputStream originalOutputStream = originalLoggableWriter.getOutputStream();
      final OutputStream wrappedOutputStream = new OutputStream() {
        private final ByteToCharConverter byteToCharConverter = new ByteToCharConverter(charset);

        @Override
        public void close() throws IOException {
          originalOutputStream.close();
        }

        @Override
        public void flush() throws IOException {
          originalOutputStream.flush();
        }

        @Override
        public void write(int b) throws IOException {
          originalOutputStream.write(b);
          writeToListener(ByteBuffer.wrap(new byte[] { (byte) b }));
        }

        @Override
        public void write(byte[] b) throws IOException {
          writeImpl(b, 0, b.length);
        }

        @Override
        public void write(byte[] buf, int off, int len) throws IOException {
          writeImpl(buf, off, len);
        }

        private void writeImpl(byte[] buf, int off, int len) throws IOException {
          originalOutputStream.write(buf, off, len);
          writeToListener(ByteBuffer.wrap(buf, off, len));
        }

        private void writeToListener(ByteBuffer byteBuffer) {
          CharBuffer charBuffer = byteToCharConverter.convert(byteBuffer);
          listener.addContent(charBuffer);
        }
      };
      return new LoggableOutputStream() {
        @Override public OutputStream getOutputStream() {
View Full Code Here

TOP

Related Classes of org.chromium.sdk.util.ByteToCharConverter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.