Read binary file information from servlet - from database accessor method

Okay, I have been working on this for awhile now and I just plain dont know what I am doing. Could someone please help me? I cannot find any examples through google or the forums for this specific type of situation( as in a servlet calls a method which gets binary file from a database).
- How do I get the inputStream into the servlet so that I can read it?
- Why am I getting the error message that OutputStream has already been called?
If someone could give me direction or simply tell me what I should look up - I would really really appreciate it.
The Servlet
response.setContentType("application/msword");
response.setHeader("Content-disposition","attachment; filename="+ file + ext);
OutputStream os = response.getOutputStream();
OOT openAttachments = searchInfo.openAttachments(newID, oot, ootNum, file, ext, os);
InputStream is2 = oot.getIs();
    byte b[] = new byte[16384];
    int numBytes;
        while((numBytes=is2.read(b))!=-1){
            os.write(b,0,numBytes);
            System.out.println("is - in while" + is);
        is2.close();
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/ootMain.jsp?newID="+newID);
dispatcher.forward(request, response);
        os.flush();
        os.close();
The Method
public OOT openAttachments(String newID, OOT oot, String ootNum, String file,
                           String ext, OutputStream os) {
    this.conn = database.SybaseDAO.grabConnection();
    String query = " edited for space'";
    state = conn.createStatement();
    rs = state.executeQuery(query);
        if(rs.next()){
           InputStream is = rs.getBinaryStream(2);
           oot.setIs(is);
           System.out.println("is - in while" + is);
           is.close();
Error Messages
(is - in while - method)    sun.jdbc.odbc.JdbcOdbcInputStream@c02a
(is2 - after - servlet)      sun.jdbc.odbc.JdbcOdbcInputStream@c02a
IOException: java.io.IOException: InputStream is no longer valid - the Statement
                                  has been closed, or the cursor has been moved
Mar 14, 2005 9:53:19 AM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: getOutputStream() has already been called for this responseThanks for your help/time -
Crystal

Here is the entire exception:
Mar 16, 2005 9:32:44 AM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: getOutputStream() has already been called for this response
     at org.apache.catalina.connector.Response.getWriter(Response.java:596)
     at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:161)
     at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:111)
     at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:122)
     at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:115)
     at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:182)
     at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:115)
     at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:75)
     at org.apache.jsp.ootMain_jsp._jspService(org.apache.jsp.ootMain_jsp:596)
     at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
     at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
     at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:302)
     at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:246)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
     at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:682)
     at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:581)
     at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:501)
     at oot.display_files.doGet(display_files.java:63)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:106)
     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
     at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:576)
     at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
     at java.lang.Thread.run(Thread.java:595)
Mar 16, 2005 9:32:44 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet display_files threw exception
java.lang.IllegalStateException: getOutputStream() has already been called for this response
     at org.apache.catalina.connector.Response.getWriter(Response.java:596)
     at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:161)
     at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:111)
     at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:122)
     at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:115)
     at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:182)
     at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:115)
     at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:75)
     at org.apache.jsp.ootMain_jsp._jspService(org.apache.jsp.ootMain_jsp:596)
     at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
     at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
     at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:302)
     at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:246)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
     at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:682)
     at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:581)
     at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:501)
     at oot.display_files.doGet(display_files.java:63)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:106)
     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
     at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:576)
     at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
     at java.lang.Thread.run(Thread.java:595)Line 63 is the include...

Similar Messages

  • Read-only file access from network volume

    I get an read-only file access from network volume problem while sharing a drive from Snow Leopard to a Tiger install. Most of files were opening well, but *.fp7 (FileMaker) and *.xls (Excel) files won't open dealing with a read-only error.
    As descibed in the last post of http://discussions.apple.com/thread.jspa?threadID=1406977 the client have the same share name of the server. Renomming it resolved the error!
    Thanks!

    right then, as it looks like I'm talking to myself....
    I have just wiped clean the Macbook Pro.
    I installed Leopard from scratch, then installed Office 2008.
    Logged back onto the network share, and the read-only error came up again, ONLY in Excel.
    bugger.
    Did the same thing with my Macbook and all is fine.
    Copy the file to the local hard drive, opens ok.
    I then copied the file to another Mac on the network.
    mmmm, opens fine.
    what's the difference....
    mmmm, the machine it opens fine from is running 10.4
    the machine which hosts all the data is running 10.3.9
    could this be the problem.
    Just done a software update check on the 10.3 machine and there are some security updates that need doing.
    Going to run that now and see what happens, otherwise I think the iMac running 10.3.9 is going to need to come up to 10.4 and fingers crossed this will solve it.

  • How i can enter information from Database to jtree and update it

    How i can enter information from Database to jtree and update it

    Is the memory cache enabled (about:cache)?<br />
    You can open about: pages via the location bar like you open a website.
    *http://kb.mozillazine.org/browser.cache.memory.enable

  • How to synchronize if one servlet read a file and anothe servlet update the

    How to synchronize if one servlet read a file and anothe servlet update the file at a time?

    Create a class that holds the reference to the file and do the whole file manipulation just in that class. than synchronize the read and write methodes. A reference to this file handler class can be stored to the servlet context in one servlet and read out from the servlet context in the other servlet.

  • Read binary file 10 bytes at a time

    I want to read binary file in a specific format. There is a number at the starting of the file. That tells us where the data is starting. Suppose it says 3975, then it mean data starts at 3975. Then once I read that location I want to read data at 10bytes at a time and then convert it to numeric and display it on graph. I am attaching the file format and the current vi which I am using. please help.
    Solved!
    Go to Solution.
    Attachments:
    topo.zip ‏89 KB

    Ah, the first 10 characters are a string!
    After opening the file, use the Read From Text File with count set to 10.  Then use the Decimal String to Number to convert this string into your "record size".
    NOTE:  The text indicator was just for debug purposes.  You don't really need it.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    Read record size.png ‏12 KB

  • How to open and read binary files?

    How do I open and read Binary files?

    Did you  look on The Unarchiver's web site where it has a link to older versions? http://theunarchiver.googlecode.com/files/TheUnarchiver3.2_legacy.zip
    The best thing to do is ask your friends what programs they used to produce these files, or at least what format files they are producing.  Otherwise it's like being shown a car and given a bundle of 200 keys with no idea to which one to use, or even if any of them work with that car.
    Using The Unarchiver will likely not do anything because it too will not know what format files are involved, and they may not even been in an archived format.  If they sent you a Word file without telling you (a favorite of Windows users to do  -- it drives me crazy when they could have just sent them in plain text), The Unarchiver won't open them.  If it's a picture file then using Hexedit will just show you a bunch of unintelligible stuff as shown in an earlier post, though you may see a line of text providing a hint.
    As I said earlier, often .bin may be an executable program which needs another program to actually interpret it.  That's what Java is trying to do.  Still, it may think it can execute the file, but it is highly unlikely somebody would send you an executable program (and if they did I would not trust it).  For all you know it may be a Windows virus.

  • Labview 8.2 Read Binary File, no pos offset option anymore?!

    I have a VI that worked perfectly well in 7.1 and now I've opened it in 8.2 it doesn't work and I can't revert back to 7.1 because I accidently pressed save.
    In 7.1 I used the combination of open, read and close file functions to read parts of a large binary data file - I cannot read the whole file into Labview 8.2 as it fills the memory. There isn't a terminal in the 'read binary file' function in 8.2 for 'pos offset' which is what I used to use in 7.1. How am I supposed to open the file now? Surely they have not removed such a useful facility entirely - is there another way to do it that I am not aware of?
    Many thanks in advance for help,
    Sarah

    smercurio_fc wrote:
    André, at first I could not understand your response, ...
    Must be my Dutch way of writing English
    Regards,
    André
    Using whatever version of LV the customer requires. (LV5.1-LV2012) (www.carya.nl)

  • Read binary file in LabVIEW 2012

    Hi,
    Have anyoune experienced problems reading binary files in 2012 previously saved in 2010.
    As shown on attached image, the same VI is opened in 2010 and 2012 reading the same binary file containing the data structure "ProcessList IN".
    I suspect it has something to do with the variants ?
    The error message does help a lot (-;
    Any ideas ?
    Kind regards
    Kahr
    Regards Kahr
    Certified LabVIEW Architect
    CIM A/S
    Attachments:
    Read_Binary_File_Error_LV2012.png ‏426 KB

    Hi Kahr,
    "error 1" tells one of the input parameters is wrong: it's either the path or the cluster datatype! The error message only mentions a file path AS AN EXAMPLE!
    You're using BinaryRead similar to those old Datalog file functions to read a cluster of several data. It has been know that datalog files get tricky when one is using a different LabVIEW version to read them due to changes of internal data representation. Maybe that's the point that hits you now?
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Reading binary files

    Hi
    I need some help in reading binary files. This is the code I have so far.
    import java.io.InputStream;
    import java.io.FileInputStream;
    import java.io.IOException;
    public class patternmatch {
         public static void main (String[] args) {   
              final byte[] bytes = new byte[1];
              try {     
                   final InputStream  instream = new FileInputStream  (args[0]);
                   while (true) {
                        final int count = instream.read (bytes);
                        if (count==-1) break;
                        System.out.println(bytes);
                   instream.close();       
              } catch (IOException e) {
                   System.err.println(e);         
    }Instead of a list of hexadecimal numbers that I want I get a long line of
    [B@eee36c
    [B@eee36c
    [B@eee36c
    [B@eee36c
    Which represents some address I think.
    Does anyone know how to extract the hexidecimal numbers?
    Thanks
    Charles

    double post http://forum.java.sun.com/thread.jsp?forum=31&thread=558802

  • Reading MP3 header information from file

    Hi,
    Im currently using the JMF bean to play a specified location. Such as a media player would do. Now I would like to read the ehader information of MP3 files - if provided as a source. How can I access this data ?
    thanks,
    detlef

    You need to read about the .DWG file format somewhere. Use some binary file editor like Ultraedit and try to understand the file's layout.
    Hint: if it is a binary format, do not use "readLine". Read the raw bytes and try to get the structure of the file piecewise.

  • Reading and extracting information from pdf file

    Hi everybody!
    what am looking for is Java packages which can allow me to read and extract information form pdf file
    I would really appreciate link wtih sample code
    thanks in advance!

    STFW.
    http://www.google.com/search?q=java+read+pdf&sourceid=mozilla-search&start=0&start=0&ie=utf-8&oe=utf-8

  • Write to binary file different from 8.0 to 8.2?

    I am communicating with a device via USB and am using a method setup by the USB driver programmer. To communicate, I write to a binary file with a filename of \\?\COMx. This has been working fine for about a  year in mfg with Labview 8.0. I recently "upgraded" to 8.2 and now it does not work. If I save for a previous version and run 8.0 it works fine. How can I make this work with 8.2?

    Yi Y,
    The USB device is one of the instruments we manufacture. The USB driver is written so writing to the USB port is just like writing to a file. I use the binary read/write VI's to send and receive commands to this USB device. The filename I use is \\?\COM#. I am told by the USB driver creator that this is common for low level C. I have been using this VI for that last year and recently upgraged from 8.0 to 8.2 and it does not work. I run the same vi under 8.0 and it works fine. This is not a common way to communicate, so will probably not get an answer.
    My next question is, is there any way to run an 8.0 dll or vi from an 8.2 executable?
    Thanks
    Hi dgtest1,
    Which USB device you are using, and which driver are you using? I'm trying to figure out specifically how you are communicating with the USB device by writing a binary file and how was the binary file written.  Could you please post more information to describe in more details about what your set up is doing?
    Thanks!
    Yi Y.
    Applications Engineer
    National Instruments
    http://www.ni.com/support

  • File direct from database to open/save, without tempfile

    Hello, everyone.
    I've got the file uploading to the database, and that is working most excellent.
    How do I get it to open/save immediately without first using CFFILE action="write" to save it to a server folder, first?
    I'm using the following code:
    <cfcontent variable="#getFile.contents#" reset="true"><!--- binary data for file, pulled from "varbinary(max)" --->
    <cfheader name="content-disposition" value="attachment;filename=#getFile.fileName#">
    <cfheader name="content-type" value="application/octet-stream">
    <cfoutput>#toString(getFile.contents)#</cfoutput>
    <cfabort>
    .. but all this does is open a dialogue asking the user to either open or save the CFM file calling it, but the .cfm is replaced with .ZIP.
    The files are not all going to be the same MIMEtype - some will be Word documents, some Excel documents, some PowerPoint documents, and some PDF documents.
    ^_^

    Filetypes that can be uploaded into the database are PDF, PPT, DOC/DOCX, and XLS/XLSX (PDF, PowerPoint, Word, Excel).  I am setting the MIMEtype by using a CFC I built that creates an array of extensions and the MIMEtypes they are associated with (for example, if the filename ends in .DOCX, the array returns a MIMEtype of "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; if the filename ends in .DOC, the array returns a MIMEtype of "application/msword"; if the filename ends in .PDF, the array returns a MIMEtype of "application/pdf".  The CFCONTENT tag is then set for that type.)
    This is an internal web app that cannot be accessed outside of this network.  Every computer that has access to it has Office 2007 installed, as well as Adobe Reader, so when given the option to open or save, the "open" is always associated with the proprietary application (.xls is always given an option for Microsoft Excel; .docx is always given an option for Microsoft Word; etc.)
    Theoretically, once the binary of the Excel/Word/PowerPoint/PDF file is stored in the database, I should be able to read that binary data, give it the CFCONTENT and CFHEADER tags that it needs, and it should download and save, or open in the native application (this much is working.)  What is confusing me is why the applications feel that the files are corrupted and need to be recovered.  The file is being insert as binary, being retrieved as binary.  What _could_ cause the data to be misconstrued as corrupted?  I'm _not_ using TRIM for insert or select, or any kind of encoding/decoding.
    ^_^

  • Error while opening PDF file downloaded  from database Blob column

    Hi All,
    I am working on jdev 11.1.1.4.0.
    In my use-case I am using filedownload Actionlistner on a link to get the PDF file stored in the database in blob field. These files are being uploaded from other use-case in adf only.
    After getting the dialog box to open/save/cancel for the PDF file when i click on open then i am getting an error *'Adobe Reader could not open 'abc.pdf' because it is either not a supported file type*
    or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly docoded)' for some files , and to my surprise I am able to open some files.
    When I open these PDF files separately from desktop I am able to view the content of each and every file in adobe reader.
    I dont know where the problem exactly lies , while uploading/downloading the file . Any ideas/thoughts to resolve this issue?
    Thanks
    Kanika

    Thanks a lot Timo...!!!
    I checked the PDF file downloaded directly from the blob column in DB, there only it is corrupted so must be the problem in uploading the file. I am checking the code line by line,, but no problem in setting the file content type,size etc.
    Here is the code snippet ..
    byte[] buff;
    buff = new byte[(int)length]; -- Length is the file size
    int bytesRead = is.read(buff);
    for (int i = 0; bytesRead < buff.length; i++) {
    // int b = is.read();
    int b = is.read();
    if (b == -1)
    break;
    buff[i] = (byte)b;
    BlobDomain blobDomian = new BlobDomain((buff));
    TestVORow = (TestVORow Impl)TestVO.createRow();
    if(blobDomian != null) {
    TestVORow.setAttachment(blobDomian);
    am.getTransaction().commit();
    This seems to be Ok to me..the same issue, file is still corrupting.
    Any thoughts from your side ???
    Thanks
    Kanika
    The problem is resolved.
    Changes made are instead of
    InputStream is;
    used ... BufferedInputStream bis ;
    and after
    for (int i = 0; bytesRead < buff.length; i++) {
    // int b = bis.read();
    int b = bis.read();
    if (b == -1)
    break;
    buff[i] = (byte)b;
    bis.close(); // use this close bufferedInput Stream.
    Able to open each and every file now..Thanks for your suggestions Timo and Frank.
    Edited by: Kanika on Mar 6, 2012 3:15 AM

  • Problems reading non-english fields from database on Unix platform

    Hello!
    I am trying to get some data(not in English) from the database and write it to the file. I use ResultSet for that perpose. On PC the program runs all right, but when I run it on Unix, I get garbage instead of letters in my output file. I tried different combinations: such methods of ResultSet like getString, getAsciiStream, getBinaryStream, getCharacterStream and encodings like
    String str = new String(rs.getBytes(), "USO-8859-1"/"UTF-8").
    Nothing helps!
    There is either garbage or "?" instead of letters.

    Hi,
    I think that It comes from your unix system that don't support accentuated characters (and your code can't resolve it).
    You can search in this way...

Maybe you are looking for