Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
I have the following code which reads in the follow file, append a \r\n to the end of each line and puts the result in a string buffer: public InputStream getInputStream() throws Exception { StringBuffer holder = new StringBuffer(); try{ FileInputStream reader = new FileInputStream(inputPath); BufferedReader br = new BufferedReader(new InputStreamReader(reader)); String s...
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 ...
How would I go on doing this? .tns is used by TI-Nspire (math-software) created by Texas Instruments. If any libraries exist it would be awesome. Otherwise, how would I go on doing this preferably only with the standard Java library? Any hints? Thanks, Mike.
I have a server-client architecture where the client sends an XML to the server who reads it and generates a PDF out of it and sends that back to the client. On the client side: JAXBElement<Xml> xml = ... Socket sock = ... Marshaller marshaller = ... marshaller.marshal(xml, sock.getOutputStream()); sock.shutdownOuput(); Meanwhile on the server side: ServerSocket server = ... Sock...
I have some badly formatted XML that I must parse. Fixing the problem upstream is not possible. The (current) problem is that ampersand characters are not always escaped properly, so I need to convert & into &amp; If &amp; is already there, I don't want to change it to &amp;amp;. In general, if any well-formed entity is already there, I don't want to destroy it. I don't think ...
This code is running on Blackberry JDE v4.2.1 It's in a method that makes web API calls that return XML. Sometimes, the XML returned is not well formed and I need to strip out any invalid characters prior to parse. Currently, I get: org.xml.sax.SAXParseException: Invalid character '' encountered. I would like to see ideas of a fast way to attach an invalid character stripper on the input st...
I have an InputStream which takes the html file as input parameter. I have to get the bytes from the input stream . I have a string: "XYZ". I'd like to convert this string to byte format and check if there is a match for the string in the byte sequence which I obtained from the InputStream. If there is then, I have to replace the match with the bye sequence for some other string. Is there any...
I have the following class subclass of FilterInputStream with only one method overrided. However the performance of this class is so poor. It performs at 1/10 the speed of its superclass. I even took the same source code from InputStream of javasrc and used it in my subclass. Same performance hit. Is there something wrong with overriding classes? public class NewLineStream extends FilterInputS...
I'm trying to organize filter chain of EventQueue.dispatchEvent. Something like java.io.FilterInputStream or javax.servlet.Filter. Found EventQueueDelegate.Delegate to be intended for this?.. But it in case of exception in EventQueue.dispatchEvent EventQueueDelegate.Delegate knows nothing about this and ugly java.awt.EventDispatchThread.handleException appears on the scene. Is this 'temp...
Is there a way to limit the maximum buffer size to be read from an ObjectInputStream in java? I want to stop the deserialization if it becomes clear that the Object in question is crafted maliciously huge. Of course, there is ObjectInputStream.read(byte[] buf, int off, int len), but I do not want to suffer the performance penalty of allocating, say byte[1000000]. Am I missing something here?
I have a SAX DefaultHandler which parses an InputStream. I don't know how many elements are in the XML so I can't count them on endElement or simmilar. I do know the byte length of the InputStream (read from the http header) but I can't find a method to get the current bytewise progress of the parsing process. Is there a way to get the current progress (i.e. bits processed) of the parsing proc...
I've been making an image rescaler that uses the ImageIO library in Java to convert them to a buffered image. Unfortunately it doesn't recognise every type of JPEG that I may pass to it and so I need to "convert" these other types. The way I'm converting them is to take an existing APP0 tag from a standard JFIF JPEG and what I want to do is on the 3rd byte into the file insert 18 bytes of dat...
My free webhost appends analytics javascript to all PHP and HTML files. Which is fine, except that I want to send XML to my Android app, and it's invalidating my files. Since XML is parsed in its entirety (and blows up) before passed along to my SAX ContentHandler, I can't just catch the exception and continue merrily along with a fleshed out object. (Which I tried, and then felt sheepish abo...
Is it possible to initialize an inputstream via another inputstream in java ?
I have a Java application running which fetches data by XML, but once in a while i have some data consisting some sort of control code? An invalid XML character (Unicode: 0x6) was found in the CDATA section. org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x6) was found in the CDATA section. at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)...
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...
How can i get the size of an Document object? DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); InputStream iStr = urlConnection.getInputStream(); doc = db.parse(iStr); ???? --> Log.i("Bytes",String.valueOf(doc.get????));
  /*
   * Copyright 1994-2006 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;

A FilterInputStream contains some other input stream, which it uses as its basic source of data, possibly transforming the data along the way or providing additional functionality. The class FilterInputStream itself simply overrides all methods of InputStream with versions that pass all requests to the contained input stream. Subclasses of FilterInputStream may further override some of these methods and may also provide additional methods and fields.

Author(s):
Jonathan Payne
Since:
JDK1.0
 
 public
 class FilterInputStream extends InputStream {
    
The input stream to be filtered.
 
     protected volatile InputStream in;

    
Creates a FilterInputStream by assigning the argument in to the field this.in so as to remember it for later use.

Parameters:
in the underlying input stream, or null if this instance is to be created without an underlying stream.
 
     protected FilterInputStream(InputStream in) {
         this. = in;
     }

    
Reads the next byte of data from this input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

This method simply performs in.read() and returns the result.

Returns:
the next byte of data, or -1 if the end of the stream is reached.
Throws:
IOException if an I/O error occurs.
See also:
in
 
     public int read() throws IOException {
         return .read();
     }

    
Reads up to byte.length bytes of data from this input stream into an array of bytes. This method blocks until some input is available.

This method simply performs the call read(b, 0, b.length) and returns the result. It is important that it does not do in.read(b) instead; certain subclasses of FilterInputStream depend on the implementation strategy actually used.

Parameters:
b the buffer into which the data is read.
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
Throws:
IOException if an I/O error occurs.
See also:
read(byte[],int,int)
    public int read(byte b[]) throws IOException {
        return read(b, 0, b.length);
    }

    
Reads up to len bytes of data from this input stream into an array of bytes. If len is not zero, the method blocks until some input is available; otherwise, no bytes are read and 0 is returned.

This method simply performs in.read(b, off, len) and returns the result.

Parameters:
b the buffer into which the data is read.
off the start offset in the destination array b
len the maximum number of bytes read.
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
Throws:
java.lang.NullPointerException If b is null.
java.lang.IndexOutOfBoundsException If off is negative, len is negative, or len is greater than b.length - off
IOException if an I/O error occurs.
See also:
in
    public int read(byte b[], int offint lenthrows IOException {
        return .read(bofflen);
    }

    

This method simply performs in.skip(n).

    public long skip(long nthrows IOException {
        return .skip(n);
    }

    
Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream. The next caller might be the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.

This method returns the result of in.available().

Returns:
an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking.
Throws:
IOException if an I/O error occurs.
    public int available() throws IOException {
        return .available();
    }

    
Closes this input stream and releases any system resources associated with the stream. This method simply performs in.close().

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

    
Marks the current position in this input stream. A subsequent call to the reset method repositions this stream at the last marked position so that subsequent reads re-read the same bytes.

The readlimit argument tells this input stream to allow that many bytes to be read before the mark position gets invalidated.

This method simply performs in.mark(readlimit).

Parameters:
readlimit the maximum limit of bytes that can be read before the mark position becomes invalid.
See also:
in
reset()
    public synchronized void mark(int readlimit) {
        .mark(readlimit);
    }

    
Repositions this stream to the position at the time the mark method was last called on this input stream.

This method simply performs in.reset().

Stream marks are intended to be used in situations where you need to read ahead a little to see what's in the stream. Often this is most easily done by invoking some general parser. If the stream is of the type handled by the parse, it just chugs along happily. If the stream is not of that type, the parser should toss an exception when it fails. If this happens within readlimit bytes, it allows the outer code to reset the stream and try another parser.

Throws:
IOException if the stream has not been marked or if the mark has been invalidated.
See also:
in
mark(int)
    public synchronized void reset() throws IOException {
        .reset();
    }

    
Tests if this input stream supports the mark and reset methods. This method simply performs in.markSupported().

Returns:
true if this stream type supports the mark and reset method; false otherwise.
See also:
in
InputStream.mark(int)
InputStream.reset()
    public boolean markSupported() {
        return .markSupported();
    }
New to GrepCode? Check out our FAQ X