Code example for ByteArrayOutputStream

Methods: size, write

0
            socketOut.write(hex, cursor, 8 - cursor);
        } 
        private byte[] hex = new byte[8];
 
        private void sendCache(boolean close) throws IOException {
            int size = cache.size();
            if (size > 0 || close) {
                if (limit < 0) {
                    if (size > 0) {
                        writeHex(size);
                        socketOut.write(CRLF);
                        cache.writeTo(socketOut);
                        cache.reset();
                        socketOut.write(CRLF);
                    } 
                    if (close) {
                        socketOut.write(FINAL_CHUNK);
                    } 
                } 
            } 
        } 
 
        @Override 
        public synchronized void flush() throws IOException { 
            checkClosed(); 
            if (writeToSocket) {
                sendCache(false); 
                socketOut.flush();
            } 
        } 
 
        @Override 
        public void flushToSocket() throws IOException  { 
            if (isCached()) { 
                cache.writeTo(socketOut);
            } 
        } 
 
        @Override 
        public synchronized void close() throws IOException { 
            if (closed) {
                return; 
            } 
            closed = true;
            if (writeToSocket) {
                if (limit > 0) {
                    throw new IOException(Msg.getString("K00a4"));
                } 
                sendCache(closed);
            } 
            // BEGIN android-added 
            /* 
             * Note: We don't disconnect here, since that will either 
             * cause the connection to be closed entirely or returned 
             * to the connection pool. In the former case, we simply 
             * won't be able to read the response at all. In the 
             * latter, we might end up trying to read the response 
             * while, meanwhile, the connection has been handed back 
             * out and is in use for another request. 
             */ 
            // END android-added 
            // BEGIN android-deleted 
            // disconnect(false); 
            // END android-deleted 
        } 
 
        @Override 
        public synchronized void write(int data) throws IOException {
            checkClosed(); 
            if (limit >= 0) {
                if (limit == 0) {
                    throw new IOException(Msg.getString("K00b2"));
                } 
                limit--;
            } 
            cache.write(data);
            if (writeToSocket && cache.size() >= cacheLength) {
                sendCache(false); 
            } 
        } 
 
        @Override