java.io

Class OutputStream

Implemented Interfaces:
Closeable, Flushable
Known Direct Subclasses:
ByteArrayOutputStream, ByteArrayOutputStream, ByteBuffer, ChunkedOutputStream, ClosedOutputStream, CountingOnlyOutputStream, DemuxOutputStream, DocumentOutputStream, FastByteArrayOutputStream, FileBufferedOutputStream, FileOutputStream, FileOutputStreamProxy, FilterOutputStream, JRPdfExporter.NullOutputStream, NullOutputStream, ObjectOutputStream, OutputStreamCounter, OutputStreamEncryption, PipedOutputStream, RamFileOutputStream, ResponseStream, RubyOutputStream, ServletOutputStream, ThresholdingOutputStream

public abstract class OutputStream
extends Object
implements Closeable, Flushable

This abstract class is the superclass of all classes representing an output stream of bytes. An output stream accepts output bytes and sends them to some sink.

Applications that need to define a subclass of OutputStream must always provide at least a method that writes one byte of output.

Since:
JDK1.0
See Also:
BufferedOutputStream, ByteArrayOutputStream, DataOutputStream, FilterOutputStream, InputStream, write(int)

Method Summary

void
close()
Closes this output stream and releases any system resources associated with this stream.
void
flush()
Flushes this output stream and forces any buffered output bytes to be written out.
void
write(b[] )
Writes b.length bytes from the specified byte array to this output stream.
void
write(b[] , int off, int len)
Writes len bytes from the specified byte array starting at offset off to this output stream.
abstract void
write(int b)
Writes the specified byte to this output stream.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Method Details

close

public void close()
            throws IOException
Closes this output stream and releases any system resources associated with this stream. The general contract of close is that it closes the output stream. A closed stream cannot perform output operations and cannot be reopened.

The close method of OutputStream does nothing.

Specified by:
close in interface Closeable
Throws:
IOException - if an I/O error occurs.
Usages and Demos :

View More Examples of close()
   1:       Socket s = new Socket("metalab.unc.edu", 80);
   2:       OutputStream out = s.getOutputStream();
   3:         ...
   4:       out.close();
   5:       InputStream in = s.getInputStream();
   6:       
   7:     }

View Full Code Here
   1: import java.io.InputStream;
   2: import java.io.OutputStream;
   3: 
   4:         ...
   5: public class Util {
   6:     public static void copyStream( InputStream in, OutputStream out, boolean closeOut ) throws IOException {
   7:         byte[] buf = new byte[256];
   8:         ...
   9:         }
  10:         in.close();
  11:         if(closeOut)
  12:         ...
  13:             out.close();

View Full Code Here
   1:     InputStream  in  = socket.getInputStream();
   2:     OutputStream out = socket.getOutputStream();
   3:     
   4:         ...
   5:     
   6:     in.close();
   7:         ...
   8:     out.close();
   9:   }

View Full Code Here
   1:     
   2:     OutputStream  out  = new FileOutputStream( "c:/screenshot.jpg" );
   3:     JPEGCodec.createJPEGEncoder( out ).encode( bi );
   4:         ...
   5:     out.close();
   6: 
   7: 
   8:     System.exit( 0 );

View Full Code Here
   1: 
   2:     OutputStream out = new GZIPOutputStream( response.getOutputStream() );
   3:     out.write( txt );
   4:         ...
   5:     out.close();
   6:   }
   7: }

View Full Code Here

flush

public void flush()
            throws IOException
Flushes this output stream and forces any buffered output bytes to be written out. The general contract of flush is that calling it is an indication that, if any bytes previously written have been buffered by the implementation of the output stream, such bytes should immediately be written to their intended destination.

If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.

The flush method of OutputStream does nothing.

Specified by:
flush in interface Flushable
Throws:
IOException - if an I/O error occurs.
Usages and Demos :

View More Examples of flush()
   1: 
   2:   public CodecOutputStream(OutputStream out)
   3:   {
   4:         ...
   5:     out.write(b, off, newlen);
   6:     out.flush();
   7: System.out.println("Flushed");
   8:   }
   9: }

View Full Code Here
   1: 
   2:     OutputStream seqOut = new FileOutputStream(new File(args[1]));
   3: 
   4:         ...
   5: 
   6:     seqOut.flush();
   7:     seqOut.close();
   8:   }
   9: }

View Full Code Here
   1:       URL u = new URL(args[0]);
   2:       OutputStream out = new FileOutputStream(args[1]);
   3:       InputStream in = u.openStream();
   4:         ...
   5:       in.close();
   6:       out.flush();
   7:       out.close();
   8:     }
   9:     catch (ArrayIndexOutOfBoundsException e) {

View Full Code Here
   1: 
   2: import java.io.OutputStream;
   3: import java.io.IOException;
   4:         ...
   5:       Socket socket = new Socket("127.0.0.1", port);
   6:       OutputStream stream = socket.getOutputStream();
   7:       String shutdown = "SHUTDOWN";
   8:         ...
   9:         stream.write(shutdown.charAt(i));
  10:       stream.flush();
  11:       stream.close();

View Full Code Here
   1: 
   2: import java.io.OutputStream;
   3: import java.io.IOException;
   4:         ...
   5: 
   6: public final class ForkOutputStream extends OutputStream {
   7:         ...
   8:     final OutputStream out1,out2;
   9: 
  10:         ...
  11:     public void flush() throws IOException {
  12:         out1.flush();

View Full Code Here

write

public void write(b[] )
            throws IOException
Writes b.length bytes from the specified byte array to this output stream. The general contract for write(b) is that it should have exactly the same effect as the call write(b, 0, b.length).
Parameters:
Throws:
IOException - if an I/O error occurs.
See Also:
java.io.OutputStream.write(byte[], int, int)
Usages and Demos :

View More Examples of write(b[] )
   1: import java.io.FileOutputStream;
   2: import java.io.OutputStream;
   3: import java.util.Enumeration;
   4:         ...
   5: 
   6:     private static OutputStream os=null;
   7:     private static final Hashtable entries=new Hashtable();
   8:         ...
   9:             os.write("Key:      Number of calls:    Total time (ms): Average time (ms):\n".getBytes());
  10:             os.write("-----------------------------------------------------------------\n\n".getBytes());
  11:         }

View Full Code Here
   1: import java.io.IOException;
   2: import java.io.OutputStream;
   3: 
   4:         ...
   5: 
   6:     public static void dump(byte data[], OutputStream out) throws IOException {
   7:         dump(data, 0, data.length, out);
   8:         ...
   9: 
  10:     public static void dump(byte[] data, int off, int len, OutputStream out) throws IOException {
  11:         String hexoff;
  12:         ...
  13:             }
  14:             out.write((hexoff + " ").getBytes());

View Full Code Here
   1: import java.io.IOException;
   2: import java.io.OutputStream;
   3: import java.math.BigInteger;
   4:         ...
   5:                 response.setContentLength(data.length);
   6:                 response.getOutputStream().write(data);
   7:             } else if(csrId != null){
   8:         ...
   9:                 response.setContentType("multipart/mixed; boundary=\"BOUNDARY\"");
  10:                 OutputStream out = response.getOutputStream();
  11:                 out.write("This is a multi-part message in MIME format.\n".getBytes());
  12:         ...
  13: 
  14:                 out.write("--BOUNDARY\n".getBytes());

View Full Code Here
   1:             ejbOut.flush();
   2:             fos2.write(ejbOut.toByteArray());
   3: 
   4:         ...
   5: 
   6:     public static void writeBuffer(OutputStream fos3, int[] buf) throws IOException{
   7: 
   8:         ...
   9:             c = c.substring(c.length() - columnWidth);
  10:             fos3.write(c.getBytes());
  11:         }
  12:         ...
  13: 
  14:         fos3.write("     ".getBytes());

View Full Code Here
   1: import java.io.IOException;
   2: import java.io.OutputStream;
   3: 
   4:         ...
   5:                     out.write("public static ");
   6:                     out.write(rt.getJavaClass().getName());
   7:         ...
   8:                     out.write(" func(");
   9:                     if (at.length!=0) {
  10:         ...
  11:                         int i=0;
  12:                         out.write(at[i].getJavaClass().getName());

View Full Code Here

write

public void write(b[] ,
                  int off,
                  int len)
            throws IOException
Writes len bytes from the specified byte array starting at offset off to this output stream. The general contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation.

The write method of OutputStream calls the write method of one argument on each of the bytes to be written out. Subclasses are encouraged to override this method and provide a more efficient implementation.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Parameters:
off - the start offset in the data.
len - the number of bytes to write.
Throws:
IOException - if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.
Usages and Demos :

View More Examples of write(b[] ,int off,int len)
   1: {
   2:   private OutputStream delegate_;
   3: 
   4:         ...
   5:   {
   6:     delegate_.write(_b,_off,_len);
   7:   }
   8: }

View Full Code Here
   1:     
   2:     public CRLFOutputStream(OutputStream out)
   3:     {
   4:         ...
   5:                 {
   6:                     out.write(b, d, (i-d)+1);
   7:                     out.write(LF);
   8:         ...
   9:               case LF:
  10:                 out.write(b, d, i-d);
  11:         ...
  12:                 out.write(CRLF, 0, 2);

View Full Code Here
   1: import java.io.IOException;
   2: import java.io.OutputStream;
   3: import java.io.UnsupportedEncodingException;
   4:         ...
   5: 
   6:   public CRLFOutputStream(OutputStream out)
   7:   {
   8:         ...
   9:           case CR:
  10:             out.write(b, d, i - d);
  11:         ...
  12:             out.write(CRLF, 0, 2);

View Full Code Here
   1: import java.io.InputStream;
   2: import java.io.OutputStream;
   3: import java.net.InetAddress;
   4:         ...
   5:                     InputStream in=null;
   6:                     OutputStream out=null;
   7:                     try {
   8:         ...
   9:                         int b=in.read();
  10:                         out.write(RSP_BUF, 0, RSP_BUF.length);
  11:                     }
  12:         ...
  13: 
  14:         OutputStream out=null;

View Full Code Here
   1: import java.io.IOException;
   2: import java.io.OutputStream;
   3: 
   4:         ...
   5: 
   6: public class ChunkedOutputStream extends OutputStream {
   7: 
   8:         ...
   9: 
  10:     private OutputStream stream = null;
  11: 
  12:         ...
  13:                     Integer.toHexString(cachePosition) + "\r\n");
  14:             stream.write(chunkHeader, 0, chunkHeader.length);

View Full Code Here

write

public abstract void write(int b)
            throws IOException
Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Subclasses of OutputStream must provide an implementation for this method.

Parameters:
b - the byte.
Throws:
IOException - if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
Usages and Demos :

View More Examples of write(int b)
   1: import java.io.FileOutputStream;
   2: import java.io.OutputStream;
   3: import java.util.Enumeration;
   4:         ...
   5: 
   6:     private static OutputStream os=null;
   7:     private static final Hashtable entries=new Hashtable();
   8:         ...
   9:             os.write("Key:      Number of calls:    Total time (ms): Average time (ms):\n".getBytes());
  10:             os.write("-----------------------------------------------------------------\n\n".getBytes());
  11:         }

View Full Code Here
   1: import java.io.IOException;
   2: import java.io.OutputStream;
   3: 
   4:         ...
   5: 
   6:     public static void dump(byte data[], OutputStream out) throws IOException {
   7:         dump(data, 0, data.length, out);
   8:         ...
   9: 
  10:     public static void dump(byte[] data, int off, int len, OutputStream out) throws IOException {
  11:         String hexoff;
  12:         ...
  13:             }
  14:             out.write((hexoff + " ").getBytes());

View Full Code Here
   1: import java.io.IOException;
   2: import java.io.OutputStream;
   3: import java.math.BigInteger;
   4:         ...
   5:                 response.setContentLength(data.length);
   6:                 response.getOutputStream().write(data);
   7:             } else if(csrId != null){
   8:         ...
   9:                 response.setContentType("multipart/mixed; boundary=\"BOUNDARY\"");
  10:                 OutputStream out = response.getOutputStream();
  11:                 out.write("This is a multi-part message in MIME format.\n".getBytes());
  12:         ...
  13: 
  14:                 out.write("--BOUNDARY\n".getBytes());

View Full Code Here
   1:             ejbOut.flush();
   2:             fos2.write(ejbOut.toByteArray());
   3: 
   4:         ...
   5: 
   6:     public static void writeBuffer(OutputStream fos3, int[] buf) throws IOException{
   7: 
   8:         ...
   9:             c = c.substring(c.length() - columnWidth);
  10:             fos3.write(c.getBytes());
  11:         }
  12:         ...
  13: 
  14:         fos3.write("     ".getBytes());

View Full Code Here
   1: import java.io.IOException;
   2: import java.io.OutputStream;
   3: 
   4:         ...
   5:                     out.write("public static ");
   6:                     out.write(rt.getJavaClass().getName());
   7:         ...
   8:                     out.write(" func(");
   9:                     if (at.length!=0) {
  10:         ...
  11:                         int i=0;
  12:                         out.write(at[i].getJavaClass().getName());

View Full Code Here