1 2 Previous Next 21 Replies Latest reply on Feb 7, 2008 10:03 PM by 807603

    BufferedInputStream(InputStream in)

      How to use InputStream in BufferedInputStream(InputStream in) Constructor ?
      What should be the Inputstream in value ?

      Please help.
        • 1. Re: BufferedInputStream(InputStream in)
          Any subclass of InputStream of course. Just like the method expects.
          • 2. Re: BufferedInputStream(InputStream in)
            Just look at the api docs ( http://java.sun.com/j2se/1.5.0/docs/api/java/io/InputStream.html ):
            Direct Known Subclasses:
                AudioInputStream, ByteArrayInputStream, FileInputStream,
            FilterInputStream, InputStream, ObjectInputStream, PipedInputStream, 
            SequenceInputStream, StringBufferInputStream 
            • 3. Re: BufferedInputStream(InputStream in)
              How a String which is containing some value be stored into the object of InputStream or BufferedInputStream ?

              Edited by: Monadear on Oct 5, 2007 11:38 AM
              • 4. Re: BufferedInputStream(InputStream in)
                Not 100% sure what you are asking but maybe use StringBufferInputStream?



                But note

                Deprecated. This class does not properly convert characters into bytes. As of JDK 1.1, the preferred way to create a stream from a string is via the StringReader class.

                Edited by: smithberry on Oct 5, 2007 12:40 PM
                • 5. Re: BufferedInputStream(InputStream in)
                  yes this is depreceated and i can't use it now.
                  Any other source ??
                  • 6. Re: BufferedInputStream(InputStream in)
                    Why do you want to read a String using a BufferedInputStream? It doesn't make much sense to buffer something that's already in memory.

                    Have you considered StringReader?
                    • 7. Re: BufferedInputStream(InputStream in)
                      The String which i want to use is containing my XML File. I want to get the contents of that XML File in InputStream with the help of string and parse it so that i can read its contents.
                      • 8. Re: BufferedInputStream(InputStream in)
                        Just read the file directly into the parser and avoid the intermediate String altogether. You're just wasting memory, and the solution doesn't scale to large files.
                        • 9. Re: BufferedInputStream(InputStream in)

                          The Parse function of DocumentBuilder uses InputSource, InputStream and File as its Parameter. But my requirement is to read the messages of that File from the memory and these messages(Of File) are identified by the String only.
                          So i have to Compulsory use the String.

                          Anyways thanks for the information. Will see any other source for my Parse function, thru which i can get my relevant output.
                          • 10. Re: BufferedInputStream(InputStream in)
                            Monadear wrote:

                            The Parse function of DocumentBuilder uses InputSource, InputStream and File as its Parameter. But my requirement is to read the messages of that File from the memory and these messages(Of File) are identified by the String only.
                            So i have to Compulsory use the String.
                            InputSource can be constructed from a Reader and there is a StringReader.




                            • 11. Re: BufferedInputStream(InputStream in)

                              I tried it with both as with the InputSource and InputStream, But as already mentioned in my new topic i am receiving a FATAL ERROR. If the Fatal error be solved then only i can see whether ByteArrayInputStream of InputStream or StringReader of InputSource is working for it.

                              But still if anybody has some solution regarding it. Keep replying i'll require it afterwards.

                              Thanks for your Response

                              • 12. Re: BufferedInputStream(InputStream in)
                                Continued in the 'new topic', as you haven't told us here what the 'FATAL ERROR' is.
                                • 13. Re: BufferedInputStream(InputStream in)

                                  The FATAL ERROR which i got during this is

                                  [Fatal Error] :1:1: Content is not allowed in prolog.
                                  ERROR | (NA:185) - Error Exception Catched here : org.xml.sax.SAXParseException: Content is not allowed in prolog.

                                  The java files are compiled correctly but when i want to get the desired result this error come.

                                  Any Idea about this ??
                                  • 14. Re: BufferedInputStream(InputStream in)
                                    cause of the error:

                                    After some extensive research on the web, it is found that that you are using an UTF-8 encoded file with byte-order mark (BOM). Java doesn't handle BOMs on UTF-8 files properly, making the three header bytes appear as being part of the document. UTF-8 files with BOMs are commonly generated by tools such as Window's Notepad. This is a known bug in Java, but it still needs fixing after almost 8 years...

                                    There are some hexadecimal character at the begining of the file, which is giving error"content not allowed in prolog". No solution is provided for this till now.

                                    Example: suppose your file start with <?xml version="1.0" encoding="utf-8"?>. you will see this in a editor. But if you open this file with any hexadecimal editor you will find some junk character in the start of the file.that is causing the problem


                                    1) convert your file into a string and then read the file from the forst character that in my case the first character will be "<".so the junk character will not be there in the string and then again convert it into a file.

                                    2) some people are able to solve this problem by changing the "utf-8" to "utf-16". remember only in some case. some times this problem also exits in "utf-16" file.

                                    3) some are able to solve this problem by changing the LANG to US.en.

                                    4) If the first three bytes of the file have hexadecimal values EF BB BF then the file contains a BOM.so you can also handle by your own.

                                    5)Download a hexadecimal editor and remove the BOM.

                                    6) In case you are not able to think furthe then please to more research in internet may be you find some other solution to this problem. But These solution are some type of hack not exactly a solution.
                                    1 2 Previous Next