KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > java > io > ByteArrayOutputStream

java.io
Class ByteArrayOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.ByteArrayOutputStream
All Implemented Interfaces:
Closeable, Flushable
See Also:
Top Examples, Source Code

protected byte[] buf
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public ByteArrayOutputStream()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[702]Fast way to write to a file
By jtuomy { at } siac { dot } com on 2005/08/05 11:19:18  Rate
import java.io.*; 
  
  
 public class ByteArrayOutputStreamTest 
  {  
     public static void main ( String [  ]  args )  
      {  
     try 
      {  
       ByteArrayOutputStream baos = new ByteArrayOutputStream (  ) ; 
       PrintStream ps = new PrintStream ( baos ) ; 
  
  
       // write some output 
       for  ( int i = 0; i  <  1000; i++ )  
        {  
         ps.println ( i + " ABCDEFGHIJKLMNOPQRSTUVWXYZ" ) ; 
        }  
  
  
       // now that we are done processing write the ByteArrayOutputStream to the outputstream 
       // in your case it will be the FileOutputStream 
  
  
       long start = System.currentTimeMillis (  ) ; 
  
  
       FileOutputStream fos = new FileOutputStream ( "ByteArrayOutputStreamTest" ) ; 
       baos.writeTo ( fos ) ; 
       fos.close (  ) ; 
  
  
  
       // should be so fast that we may not even see any time elapsed 
       long stop = System.currentTimeMillis (  ) ; 
       System.out.println ( "time elapsed  ( milliseconds )  = " +  ( stop - start )  ) ; 
      }  
     catch  ( FileNotFoundException fnfe )   {  System.out.println ( fnfe.getMessage (  )  ) ;  }  
     catch  ( IOException ioe )   {  System.out.println ( ioe.getMessage (  )  ) ;  }  
  
  
      }  
  }  
 


[869]Converts a SOAPMessage to a String
By Anonymous on 2004/08/25 08:51:52  Rate
// Converts a SOAPMessage to a String 
 public static String createStringFromMessage (  
   SOAPMessage msg )  throws SOAPException,  
   IOException  {  
   ByteArrayOutputStream bos = new ByteArrayOutputStream (  ) ; 
     msg.writeTo ( bos ) ; 
     return bos.toString (  ) ; 
  } 


public ByteArrayOutputStream(int size)
See Also:
IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void close()
           throws IOException
See Also:
OutputStream, Closeable
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected int count
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void reset()
See Also:
ByteArrayInputStream.count
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int size()
See Also:
count
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public byte[] toByteArray()
See Also:
size()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String toString()
See Also:
Object
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


@Deprecated
public String toString(int hibyte)
See Also:
toString(), toString(String), size()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String toString(String enc)
                throws UnsupportedEncodingException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void write(byte[] b,
                  int off,
                  int len)
See Also:
OutputStream
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void write(int b)
See Also:
OutputStream
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void writeTo(OutputStream out)
             throws IOException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags