Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.infinispan.client.hotrod.impl.transport.tcp;
  
  
SaslOutputStream.

Author(s):
Tristan Tarrant
Since:
7.0
 
 public class SaslOutputStream extends OutputStream {
 
    private static final int BUFFER_SIZE = 64 * 1024;
    private final OutputStream outStream;
    private final SaslClient saslClient;
    private final int bufferSize;
    private final ByteArrayOutputStream buffer;
 
    public SaslOutputStream(OutputStream outStreamSaslClient saslClient) {
       this. = saslClient;
       this. = new BufferedOutputStream(outStream);
       String maxSendBuf = (StringsaslClient.getNegotiatedProperty(.);
       if (maxSendBuf != null) {
            = Integer.parseInt(maxSendBuf);
       } else {
            = ;
       }
        = new ByteArrayOutputStream();
    }
 
    @Override
    public void write(int bthrows IOException {
       checkCapacity(1);
       .write(b);
    }
 
    @Override
    public void write(byte[] bthrows IOException {
       write(b, 0, b.length);
    }
 
    @Override
    public void write(byte[] bint offint lenthrows IOException {
       checkCapacity(len);
       .write(bofflen);
    }
 
    private void writeInt(int ithrows IOException {
       .write((i >>> 24) & 0xFF);
       .write((i >>> 16) & 0xFF);
       .write((i >>>  8) & 0xFF);
       .write((i >>>  0) & 0xFF);
    }
 
    private void checkCapacity(int capacitythrows IOException {
       if (.size() + capacity >= ) {
          flush();
       }
    }
 
    private void wrapAndWrite() throws IOException {
       try {
          byte[] saslToken = .wrap(.toByteArray(), 0, .size());
          writeInt(saslToken.length);
          .write(saslToken);
          .reset();
       } catch (SaslException se) {
          try {
             .dispose();
          } catch (SaslException ignored) {
          }
          throw se;
       }
    }
   
Flushes this output stream

Throws:
java.io.IOException if an I/O error occurs.
 
    @Override
    public void flush() throws IOException {
       wrapAndWrite();
       .flush();
    }

   
Closes this output stream and releases any system resources associated with this stream.

Throws:
java.io.IOException if an I/O error occurs.
 
   public void close() throws IOException {
      .dispose();
      .close();
   }
New to GrepCode? Check out our FAQ X