Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2005, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
 
 /*
  * Created on Dec 15, 2005
  */
  
 package org.jboss.remoting.transport.multiplex.utility;
 
GrowablePipedOutputStream works together with GrowablePipedInputStream like java.io.PipedInputStream and java.io.PipedOutputStream work together, so that calling GrowablePipedOutputStream.write() causes bytes to be deposited with the matching GrowablePipedInputStream. However, unlike PipedInputStream, GrowablePipedInputStream stores bytes in a ShrinkableByteArrayOutputStream, which can grow and contract dynamically in response to the number of bytes it contains.

For more information about method behavior, see the java.io.OutputStream javadoc.

Author(s):
Ron Sigal
Version:
$Revision: 1248 $

Copyright (c) 2005

 
 
 public class GrowablePipedOutputStream extends OutputStream
 {
    private GrowablePipedInputStream sink;
    private boolean connected;

Create a new GrowablePipedOutputStream.
 
    public GrowablePipedOutputStream()
    {
    }
 
   
Create a new GrowablePipedOutputStream.

Parameters:
snk
Throws:
java.io.IOException
 
    {
       this. = sink;
       sink.connect(this);
        = true;
    }
 
    
    public void write(int bthrows IOException
    {
       if ( == null)
          throw new IOException("Pipe not connected");
 
       .receive(b);
    }
 
    
    public void write(byte[] bytesthrows IOException
    {
       if ( == null)
          throw new IOException("Pipe not connected");
       
       if (bytes == null)
  	    throw new NullPointerException();
       
       .receive(bytes);
   }
   
   
   public void write(byte[] bytesint offsetint lengththrows IOException
   {
      if ( == null)
         throw new IOException("Pipe not connected");
      
      if (bytes == null)
 	    throw new NullPointerException();
      
      if ((offset < 0) || (offset > bytes.length) || (length < 0) ||
 		   ((offset + length) > bytes.length) || ((offset + length) < 0))
         throw new IndexOutOfBoundsException("offset = " + offset + 
                                             ", length = " + length +
                                             ", file buffer size: " + bytes.length);
      
      if (length == 0)
         return;
      
      .receive(bytesoffsetlength);
   }
   
   
   protected void connect(GrowablePipedInputStream sinkthrows IOException
   {
      if (sink == null)
         throw new NullPointerException();
      
      if (sink.isConnected())
         throw new IOException("Already connected");
      
      this. = sink;
       = true;
   }
   
   
   protected boolean isConnected()
   {
      return ;
   }
New to GrepCode? Check out our FAQ X