Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
What is considered the best, most comprehensive way to close nested streams in Java? For example, consider the setup: FileOutputStream fos = new FileOutputStream(...) BufferedOS bos = new BufferedOS(fos); ObjectOutputStream oos = new ObjectOutputStream(bos); I understand the close operation needs to be insured (probably by using a finally clause). What I wonder about is, is it necessary to e...
I'm extremely new to Java, and have mostly just been teaching myself as I go, so I've started building an applet. I'd like to make one that can select a file from the local disk and upload it as a multipart/form-data POST request but with a progress bar. Obviously the user has to grant permission to the Java applet to access the hard drive. Now I've already got the first part working: the user ...
I've used Jakarta commons HttpClient in another project and I would like the same wire logging output but using the "standard" HttpUrlConnection. I've used Fiddler as a proxy but I would like to log the traffic directly from java. Capturing what goes by the connection input and output streams is not enough because the HTTP headers are written and consumed by the HttpUrlConnection class, so I ...
I need to upload a file to server and monitor it's progress. i need to get a notification how many bytes are sent each time. For example in case of download i have: HttpURLConnection connection = (HttpURLConnection) m_url.openConnection(); connection.connect(); InputStream stream = connection.getInputStream(); while ((currentBytes = stream.read(byteBuffer)) > 0) { ...
We have a system where a client makes an HTTP GET request, the system does some processing on the backend, zips the results, and sends it to the client. Since the processing can take some time, we send this as a ZipOutputStream wrapping the response.getOutputStream(). However, when we have an exceptionally small amount of data in the first ZipEntry, and the second entry takes a long time, the...
is there a way to buffer a OutputStream, modify it before it is returned? Here is my code snippet: public ServletOutputStream getOutputStream() throws IOException { BufferedOutputStream buffer = new BufferedOutputStream(super.getOutputStream()); // Modify the buffer contents, before it is returned return new DelegatingServletOutputStream(buffer); } Thanks.
Following this thread. http://stackoverflow.com/questions/55709/streaming-large-files-in-a-java-servlet. Is it possible to find the total internet bandwidth available in current machine thru java? what i am trying to do is while streaming large files thru servlet, based on the number of parallel request and the total band width i am trying to reduce the BUFFER_SIZE of the stream for each requ...
im trying to do this on Android: Process p = Runtime.getRuntime().exec("sh"); DataOutputStream out = new DataOutputStream(p.getOutputStream()); out.writeBytes("something useful\n"); out.close(); p.waitFor(); out = new DataOutputStream(p.getOutputStream()); out.writeBytes("something useful\n"); out.close(); p.waitFor(); The second time I execute out.writeBytes(...
I am writing a program that will output data to a .txt file, that can be read by a person using a program like NotePad. Perhaps not necessarily ASCII, but something that the user can understand. Which one of these do I use? ByteArrayOutputStream FileOutputStream FilterOutputStream ObjectOutputStream OutputStream PipedOutputStream I have this assignment that asks me to use one of OutputStr...
I have just a quick question: Are files created before they are finished, or are they finished and then created? For example, I am attempting to create a web-based Spotify using JSpotify. I already have created an interface for it that runs off a server. When play is pressed it will play it on the server (which is great, if I wanted to create a Spotify remote) -- but I want to stream that to t...
I recently figured out how to use ObjectOutputStream and ObjectInputStream to send objects over a simple Java socket connection between a server and a client. I was wondering if I wanted to transfer an object that might be large in size, for example an image, is it possible to put a thread that keeps track of the progress of how much data has been sent/received? If the answer to this question i...
  /*
   * Copyright 1994-1999 Sun Microsystems, Inc.  All Rights Reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Sun designates this
   * particular file as subject to the "Classpath" exception as provided
   * by Sun in the LICENSE file that accompanied this code.
  *
  * This code 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 General Public License
  * version 2 for more details (a copy is included in the LICENSE file that
  * accompanied this code).
  *
  * You should have received a copy of the GNU General Public License version
  * 2 along with this work; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  * CA 95054 USA or visit www.sun.com if you need additional information or
  * have any questions.
  */
 
 package java.io;

This class is the superclass of all classes that filter output streams. These streams sit on top of an already existing output stream (the underlying output stream) which it uses as its basic sink of data, but possibly transforming the data along the way or providing additional functionality.

The class FilterOutputStream itself simply overrides all methods of OutputStream with versions that pass all requests to the underlying output stream. Subclasses of FilterOutputStream may further override some of these methods as well as provide additional methods and fields.

Author(s):
Jonathan Payne
Since:
JDK1.0
 
 public
 class FilterOutputStream extends OutputStream {
    
The underlying output stream to be filtered.
 
     protected OutputStream out;

    
Creates an output stream filter built on top of the specified underlying output stream.

Parameters:
out the underlying output stream to be assigned to the field this.out for later use, or null if this instance is to be created without an underlying stream.
 
     public FilterOutputStream(OutputStream out) {
         this. = out;
     }

    
Writes the specified byte to this output stream.

The write method of FilterOutputStream calls the write method of its underlying output stream, that is, it performs out.write(b).

Implements the abstract write method of OutputStream.

Parameters:
b the byte.
Throws:
IOException if an I/O error occurs.
 
     public void write(int bthrows IOException {
         .write(b);
     }

    
Writes b.length bytes to this output stream.

The write method of FilterOutputStream calls its write method of three arguments with the arguments b, 0, and b.length.

Note that this method does not call the one-argument write method of its underlying stream with the single argument b.

Parameters:
b the data to be written.
Throws:
IOException if an I/O error occurs.
See also:
write(byte[],int,int)
 
     public void write(byte b[]) throws IOException {
         write(b, 0, b.length);
     }

    
Writes len bytes from the specified byte array starting at offset off to this output stream.

The write method of FilterOutputStream calls the write method of one argument on each byte to output.

Note that this method does not call the write method of its underlying input stream with the same arguments. Subclasses of FilterOutputStream should provide a more efficient implementation of this method.

Parameters:
b the data.
off the start offset in the data.
len the number of bytes to write.
Throws:
IOException if an I/O error occurs.
See also:
write(int)
    public void write(byte b[], int offint lenthrows IOException {
        if ((off | len | (b.length - (len + off)) | (off + len)) < 0)
            throw new IndexOutOfBoundsException();
        for (int i = 0 ; i < len ; i++) {
            write(b[off + i]);
        }
    }

    
Flushes this output stream and forces any buffered output bytes to be written out to the stream.

The flush method of FilterOutputStream calls the flush method of its underlying output stream.

Throws:
IOException if an I/O error occurs.
See also:
out
    public void flush() throws IOException {
        .flush();
    }

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

The close method of FilterOutputStream calls its flush method, and then calls the close method of its underlying output stream.

Throws:
IOException if an I/O error occurs.
See also:
flush()
out
    public void close() throws IOException {
        try {
          flush();
        } catch (IOException ignored) {
        }
        .close();
    }
New to GrepCode? Check out our FAQ X