JSPs writing binary data

Hi,
I'm trying to develop a JSP that returns binary data in the form of a jpeg image.
I found this on google where one of the replies correctly states that to be compliant I need to use XML JSPs:
http://www.caucho.com/quercus/faq/question.xtp?question_id=1005
This is what I am now doing but I am getting exceptions about:
"java.lang.IllegalStateException: getOutputStream() has already been called for this response"
I have traced this to be on the very last line of the blah_jsp.java file created by tomcat:
"if (_jspxFactory != null) _jspxFactory.releasePageContext(pageContext);".
My code looks like this:
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="1.2">
<jsp:directive.page contentType="image/jpeg" />
<jsp:declaration><![CDATA[ .... ]]></jsp:declaration>
<jsp:scriptlet><![CDATA[
try {
updateImage();
response.getOutputStream().write( apodImageData );
} catch (Exception e) {
out.println( e.toString() );
StringWriter sr = new StringWriter();
e.printStackTrace( new PrintWriter( sr ) );
out.println( sr.toString() );
]]></jsp:scriptlet>
</jsp:root>
Any ideas? Is there a way to stop the container produced java file from tampering with out? Obviously my code is working but the final line of the container produced code is failing because I've manually been using result.getOutputStream().
Any ideas?

Have just found this after many hours of searching:
http://www.mooreds.com/weblog/archives/000018.html
The upshot is that TC4 is non compliant in this area, TC5 is fixed..

Similar Messages

  • Exception writing binary data to the output stream to client -Broken pipe

    Hi,
    I am trying to use the drag & drop feature using Contributor mode of Webcenter sites. Single Image Page Attribute is working properly where as Multiple Image Page Attribute throws the following error:
    [ERROR] [.kernel.Default (self-tuning)'] [logging.cs.satellite.request] Exception writing binary data to the output stream to client 10.191.117.106
    java.net.SocketException: Broken pipe
         at java.net.SocketOutputStream.socketWrite0(Native Method)
         at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
         at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
         at weblogic.servlet.internal.ChunkOutput.writeChunkTransfer(ChunkOutput.java:568)
         at weblogic.servlet.internal.ChunkOutput.writeChunks(ChunkOutput.java:539)
         at weblogic.servlet.internal.ChunkOutput.flush(ChunkOutput.java:427)
         at weblogic.servlet.internal.ChunkOutput$2.checkForFlush(ChunkOutput.java:648)
         at weblogic.servlet.internal.ChunkOutput.write(ChunkOutput.java:333)
         at weblogic.servlet.internal.ChunkOutputWrapper.write(ChunkOutputWrapper.java:148)
         at weblogic.servlet.internal.ServletOutputStreamImpl.write(ServletOutputStreamImpl.java:148)
         at COM.FutureTense.Servlet.ServletRequest$OutputOutputStream.write(ServletRequest.java:80)
         at COM.FutureTense.Servlet.ServletRequest.write(ServletRequest.java:1633)
         at com.openmarket.Satellite.RequestContext.write(RequestContext.java:1123)
         at com.openmarket.Satellite.BytePiece.stream(DataPiece.java:253)
         at com.openmarket.Satellite.CacheObjectImpl.stream(CacheObjectImpl.java:651)
         at com.openmarket.Satellite.Http11Responder.respondForWrapper(Http11Responder.java:142)
         at com.openmarket.Satellite.WrapperAwareResponder.respond(WrapperAwareResponder.java:36)
         at com.openmarket.Satellite.SatelliteServer.execute(SatelliteServer.java:85)
         at com.openmarket.Satellite.servlet.BaseServlet.doGet(BaseServlet.java:118)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
         at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
         at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
         at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
         at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at com.fatwire.wem.sso.cas.filter.CASFilter.doFilter(CASFilter.java:557)
         at com.fatwire.wem.sso.SSOFilter.doFilter(SSOFilter.java:51)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3730)
         at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3696)
         at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
         at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
         at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2273)
         at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
         at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1490)
         at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
         at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
    Thanks
    KarthiK

    Thank u very much,
         FileOutputStream opGif = new FileOutputStream(destFile, false);
    I have changed above line with the following line:
         PrintWriter opGif = new PrintWriter ( new FileWriter(destFile, false));
    and now this code is working very fine.
    Thanks once again...

  • Writing binary data to a file without carriage returns every 512 bytes

    Is there a VI for writing binary data to a file without carriage returns being inserted every 512 bytes?
    Thanks

    Hi Momolxg,
    I could be way off on this. I tried to simulate what you've done by
    making a for loop that would run a set number of times. For my example I
    used 1025. I wired the iteration terminal to a 'Write to SGL File.vi'
    outside the loop with indexing enabled. It wrote the SGL data from 0 to
    1024 to the file. I then read the file with a 'Read Characters from
    File.vi' and searched the output for a carriage return (0D hex). It was
    found five times. The reason why was the SGL number it was reading had a
    13 (0D hex) in it. Perhaps you're running into a similar problem?
    I tried it again, this time using the 'Write to I16 File.vi'. The
    carriage return was found five times: the 28th character the first time
    then on the 512th character four consecutive time
    s after that. I suppose
    that makes sense that you'd find a 0D in the numbers at equal spacings if
    they're incrementing this way... In this case the carriage returns you're
    seeing are actually numbers from your data.
    One big difference is that I'm using a set pattern of numbers. This
    doesn't appear to be your case. Is there a better way we can duplicate
    your problem? It sounds interesting. Again my simulation could be way
    off. (I'm also running this on LV60 for Linux so my results could be
    different)
    - Kevin
    In article <[email protected]>,
    "momolxg" wrote:
    > Is there a VI for writing binary data to a file without carriage returns
    > being inserted every 512 bytes? Thanks

  • Writing binary data to ASP file from applet through URLConnection

    Hi Everybody,
    I am facing a proble with HttpURLConnection.I want to write some binary data from applet to an ASP file.The other end ASP file read this binary data and process , Here problem is I have opened URLConnection to the page and Created OutputStream and writing byte by Write() method But other end we are not getting bytes...we are not getting error too at java side..can any body help me..do we need to set any property to URLConnection...here I am giving sample code...
    OutputStream os;
    URL uConnect2;
    HttpURLConnection hucConnect2;
    uConnect2= new URL("http://webserver/vnc/sendtoserver.asp?"); hucConnect2=(HttpURLConnection)uConnect2.openConnection();
    hucConnect2.setDoOutput(true);
    hucConnect2.setRequestMethod("POST")
    os=new DataOutputStream(hucConnect2.getOutputStream());
    os.writeBytes("Hello");
    Thanks in Advance
    Madhav

    Do you remember to flush() and close() the stream?

  • What's the fastest C function for writing binary data to disk?

    I'm acquiring data at high speeds across multiple boards and I'm having a hard time writing the data to disk fast enough to keep up. I'm programming in C in Visual Studios and I'm currently using fwrite. I have a similar system set up in LabView and my C code can't perform as well. Is there a better or faster way to write to disk in C?

    Some speculated a few years ago that there would be
    no reason to use Fortran too. :)Are you saying there's a reason to use Fortran? Help me lord!
    Anyway, they were right! The industry may be stalling, but the vision is not. The economy and many other factors are to blame for why we haven't been able to break out of the computing paradigm we're stuck in. It's like the automobile, it hasn't changed in a century. Why? $$$
    Oh, people said we'd have flying cars by now, where are they? Well we do have them! But we're too busy spending that 400 billion a year on war instead of evolving as a species.
    Anyway, when we take the next step and have true distributed computing with multi-core processors everywhere, Java will run, Java will scale, and Java will outperform ANYTHING available.
    And speaking of game programming, the PS3 developers are having a hell of a time doing the 3 CPUs. Why? Because all they've ever done is single & double processor systems. It's time to think out of the box. When a game console hits the market with 512 CPU cores, do you REALLY think C/C++ will run on that? But, Java was designed for it.
    Java = the future
    C++ = the past

  • Writing binary data in same format as with FORTRAN code

    Hello,
    I would like to write out data in a binary format that is used by FORTRAN unformatted direct access files. I have some code in FORTAN that produces the correct format; however, I have been unable to reproduce the output with a Java method.
    The FORTAN code to write an array Z is:
    REAL Z(72,46,16)
    OPEN(8,FILE='grads.dat',FORM='UNFORMATTED',
    & ACCESS='DIRECT',RECL=72*46)
    IREC=1
    DO 10 I=1,16
    WRITE (8,REC=IREC) ((Z(J,K,I),J=1,72),K=1,46)
    IREC=IREC+1
    10 CONTINUE
    The Java code I was able to come up with to write out an array arrTS produces binary data differently:
              FileOutputStream fosOut = new FileOutputStream(filename,false);
              for(int x=0; x<this.xmax; x++) {
                   for(int y=0; y<this.ymax; y++) {
                        ByteArrayOutputStream bosOut = new ByteArrayOutputStream(2);
                        DataOutputStream dos = new DataOutputStream(bosOut);
                        dos.writeFloat((float)this.arrTS[x][y]);
                        byte[] arrByte = bosOut.toByteArray();
                        fosOut.write(arrByte);
              fosOut.close();
    Any help is greatly appreciated.
    Best regards,
    Stefan

    I am using a software to read in the data that I am calculating in Java. I cannot easily change the format that software is reading; therefore, ASCII is not an option.
    The software that reads the data states something about "Little-endian". Do you which Java classes to use for that?
    Best regards,
    Stefan
    First, you need to find out the format of yourFORTRAN
    output. Is it ASCII? EBCDIC? BCD? IEEE?
    Big-endian? Little-endian?
    Until you know that you won't know which Javaclasses
    to use.Also I wouldn't be too sure different FORTRAN
    compilers use the same data format.
    In my view the best system interchange format still is
    the ASCII text file. Why don't you let the Fortran
    program use it to write its data to file. It should be
    no problem reading it from Java.

  • URGENT PLEASE HELP WRITING BINARY DATA

    I'm attaching a jsp page to download an excel file (generated using HSSF) that doesn't work. When I open t.xls in Excel it looks fine. I think the problem is with out.write.
    <%@ page import="java.io.*" %>
    <%
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-disposition", "attachment;filename=output.xl
    s");
    String fn="/tmp/t.xls";
    File fnam=new File(fn);
    FileInputStream fis=null;
    response.setContentLength((int) fnam.length());
    int iRead;
    try{
    fis= new FileInputStream(fn);
    while((iRead=fis.read()) != -1) {
    out.write(iRead);
    out.flush();
    } catch (IOException i) {
    out.println("ioexception");
    %>

    Because there is a newline between the page import line and the <% before the code...
    <%@ page import="java.io.*" %><%
    response.setContentType("application/vnd.ms-excel");
    ...

  • Writing binary data to file ???

    Hi all,
    I am facing a strange problem in my java program. Please go through the following code...
    import java.io.*;
    public class Hex2BinFile
    Hex2BinFile()
    boolean hex2bin(String source,String destFile)
    try
    PrintWriter opGif = new PrintWriter ( new FileWriter(destFile, false));
    int strlen = source.length();
    for ( int i = 0; i < strlen; i += 2)
    opGif.print((char)Integer.parseInt(source.substring(i, i+2), 16));
    opGif.flush();
    opGif.close();
    catch(Exception e)
    System.out.println(e);
    return false;
    return true;
    public static void main(String [] args)
    Hex2BinFile hbf = new Hex2BinFile();
    hbf.hex2bin("05", "/home/oracle/1.bin"); // resulting file size is 1 byte
    hbf.hex2bin("AF", "/home/oracle/2.bin"); // resulting file size is 2 byte
    This is a very simple class. In this class hex2bin() function takes hex string, and then convert it to binary value (character by character) and write binary value to a specified file.
    In the above mentioned code, in main() method, i am calling hex2bin() method twice.
    In the first call the result is satisfactory and a file (1.bin) is created with file size 1 byte as i am passing one byte hex value to this function.
    But in the second call to hex2bin(), I am also passing 1 bye hex value, and resulting file size is 2 bytes. I also observe that when I pass a value greater than '7F' hex, the resulting file size is two byte.
    What is the cause of this inconsistancy? is there any error or problem? and what is the solution? Please guide me.
    Thanks in advance...

    Thank u very much,
         FileOutputStream opGif = new FileOutputStream(destFile, false);
    I have changed above line with the following line:
         PrintWriter opGif = new PrintWriter ( new FileWriter(destFile, false));
    and now this code is working very fine.
    Thanks once again...

  • Binary Data and JSP

    Hi all I have a basic doubt. How does Servlets is preferred technology to generate binary data than JSP? Any limitation in JSP?

    Okay,
    When you write a JSP file, you type it in text, and all the text you type is sent to the client that requests your page. Everything is sent including carriage returns, spaces, tab characters and anything you have type into the file. Only things that are inside <% and %> do not get sent through. If you have several blank lines at the end of the file they will be sent to the client and may cause issues if you are writing binary data that needs to be handled by an application.
    With Servlets you have to write data to the outputstream you get from the (cant quite remember) response.getOutputStream() method. This ensures that only what you want to send gets sent to the client.
    It sepends on what you need it for. If it doesnt matter what you send through then JSP can be used to write binary data. In one application I had to send through sound files to the client and any extra data would only corrupt the sound, so it had to be sent using servlets.
    Does that help?

  • Errors and exceptions in writing large binary data on sockets!!! urgent

    hi
    I am trying to write large binary data in the form of byte arrays on sockets.
    Data is as large as 512KB(== 524288bytes) So i store the data (actually read from a file through FileInputStream ) and then write on the socket with lines like this
    DataOutputStream dos =
    new DataOutputStream(new BufferedOutputStream(sock.getOutputStream()));
    dos.write(b);
    /* suppose b is the arrayreference in which data is stored. sometimes i write with that offset + len function*/
    dos.flush();
    dos.close();
    sock.close();
    but the program is not stable: sometimes the whole 512KB is read on other side and sometimes less usually 64KB.
    The program is unthreaded.
    There is another problem : one side(reading or writing) sometimes gives error :
    java.net.SocketException: Software caused connection abort: socket write error
    please reply and reply soon and give ur suggestions
    thanks

    hi
    I am trying to write large binary data in theform
    of byte arrays on sockets.
    Data is as large as 512KB(== 524288bytes) So istore
    the data (actually read from a file through
    FileInputStream ) and then write on the socketwith
    lines like this
    DataOutputStream dos =
    new DataOutputStream(new
    BufferedOutputStream(sock.getOutputStream()));
    dos.write(b);
    /* suppose b is the arrayreference in which datais
    stored. sometimes i write with that offset + len
    function*/
    dos.flush();
    dos.close();
    sock.close();
    but the program is not stable: sometimes the whole
    512KB is read on other side and sometimes less
    usually 64KB.
    The program is unthreaded.
    There is another problem : one side(reading or
    writing) sometimes gives error :
    java.net.SocketException: Software caused
    connection abort: socket write error
    please reply and reply soon and give ursuggestions
    thanksUmm how are you reading the data on the other side?
    some of your code snippet might help. Your writing
    code seems ok. I've written a file transfer program
    in a similar fashion and have successfully testing on
    different platforms (AIX, AS400, Solaris, Windows,
    etc) without any problems and without needing to set
    the buffer sizes with files as large as 600MB and you
    said you're testing this on the loopback?
    Point here is you should never need to reset any of the default TCP options to get program correctness. The options are more for optimizations and fine tuning. If indeed you need to change the options to get your program to work, then you program wont be able to scale under different load.

  • Sending binary data from JSP (1.1)

    Hi all:
    I am using Tomcat 3.2.1 and Apache under Linux Mandrake OS.
    I have a JSP (1.1) sending binary data (GIF, PDF, DOC ..) using response.getOutputStream().write(data)
    method.
    The problem is the precompiler automatically creates the JspWriter and puts some out.write("\r\n") lines
    before I use getOutputStream method. The JVM throws an IllegalStateException because I am using both
    methods (this is from Servlet 2.2 specification).
    Must I change my code to forwarding to a servlet that make this work or is there a simple solution to
    avoid this?
    Thanks in advance.
    J.
    null

    Hi Shreeharsha
    Please refer to below docs for sending data from JSP page to RFC. In which you need to use sap connectors for connecting to SAP backend system.
    http://help.sap.com/saphelp_nw04/helpdata/en/b6/55e3952a902447847066a0df27b0d6/content.htm
    Hope it helps
    Regards
    Arun

  • Download file problem for binary data?

    Dear All,
    I have wrote a jsp file to do download page. I have used a piece of code from the JDC to this. This code will prompt the download dialog box each time user clicks the download button. The code itself will set the content type for different application. The code is like below:
    try
    java.io.File fileobj = new java.io.File(strFolder + strFile);
    response.setContentType(application.getMimeType(fileobj.getName()));
    response.setHeader("Content-Disposition","attachment; filename=\""
    + strFile + "\"");
    java.io.FileInputStream in = new java.io.FileInputStream(fileobj);
    int ch;
    while ((ch = in.read()) != -1) {
    out.write(ch);
    out.flush();
    in.close();
    } catch(Exception e)
    The code can download and handle text file correctly when it is openned in the text editor or inside the IE. But when a PDF file or Image is downloaded and openned in the PDF viewer or image viewer, it is corrupted and cannot be viewed. What is the problem? Any ideas?
    So, I wonder this code can handle binary data or not. It is seen like there is no different code to handle text and binary data in Java/Jsp.
    Thank you very much!
    Best Regards,
    Rockyu Lee
              

    Add following lines to .tld file (custom tag definition)
    <tag>
    <name>downloadbinary</name>
    <tagclass>org.rampally.DownloadBinaryTag</tagclass>
    <bodycontent>JSP</bodycontent>
    </tag>
    Add following line to JSP files.
    In JSP, keep one line of source. Make sure that there are no space and additional line feeds at the any where
    in the JSP files except JSP tags.
    <%@ taglib uri="/WEB-INF/taglibs/mb.tld" prefix="mytags" %>
    <mytags:downloadbinary />
    I am hoping that you have all required parameters such as fileName to download, etc.
    in your session or request object.
    Tag class ....
    public class DownloadBinaryTag extends TagSupport {
         public int doEndTag() throws JspException {
              // TODO: get binary data from filename or
              // binary data buffer from datase.
              // I am making it simple .. assume that it is a request parameter for
              // you test easily.
              String fileName = request.getParameter( "filename" );
              java.io.File file = new java.io.File( fileName);
              java.io.DataInputStream dis;
              try {
                   dis = new java.io.DataInputStream(new FileInputStream(fileName));
              } catch (FileNotFoundException e) {
                   // do error handling ...
                   return EVAL_PAGE;
              BinaryUtil.sendBinaryFile( dis, (HttpServletResponse) pageContext.getResponse(), contentType );
              return EVAL_PAGE;
    public class BinaryUtil
         static public void sendBinaryFile( DataInputStream dis,
                                  HttpServletResponse response,
                                  String contentType ) {
              try {
                   response.setContentType(contentType);
                   String fileName="test.pdf";
                   response.setHeader("Content-disposition", "inline; filename=" + newFileName );
                   ServletOutputStream sout = response.getOutputStream();
                   int len;
                   byte[] data = new byte[128 * 1024];
                   while ((len = dis.read(data, 0, 128 * 1024)) >= 0)
                        sout.write(data, 0, len);
                   sout.flush();
                   sout.close();
              } catch (Exception e) {
                   System.out.println(e.getMessage());
         static public void sendBinaryFile( byte[] data,
                                  HttpServletResponse response,
                                  String contentType ) {
              try {
                   response.setContentType(contentType);
                   String fileName="test.pdf";
                   response.setHeader("Content-disposition", "inline; filename=" + newFileName );
                   ServletOutputStream sout = response.getOutputStream();
                   sout.write(data);
                   sout.flush();
                   sout.close();
              } catch (Exception e) {
                   System.out.println(e.getMessage());
    You may have to change 'inline' to 'attachment' if you do not want IE to inline the document.
    That's all!!.. Hope this helps...!

  • Storing binary data to a file......

    Hi Friends,
    I am trying to make a webapp in which users can upload Videos and I can store that videos on the server. I have this bit of code:
        public ActionForward execute(
                ActionMapping mapping,
                ActionForm form,
                HttpServletRequest request,
                HttpServletResponse response) throws Exception{
                        VideoUploadForm myForm = (VideoUploadForm)form;
                        // Process the FormFile
                        FormFile myFile = myForm.getTheFile();
                        byte[] fileData    = myFile.getFileData();
      }My question is, should i store the byte array into some text file???Then how can i read it back and get the original format i.e *.avi or *.mpg.
    This might be easy,but this is my first time dealing with binary data,so your help would be appreciated.
    Thanks
    P.S: Any links would be appreciated

    Thanks BalusC,
    After lots of hardwork finally I am trying to upload the binary file in the database,but getting this error:
    java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc, file_blob) values(1, 1, 'uploaded file from user', _binary'\0\0�!\0\0�\' at line 1
            at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2928)
            at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
            at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)
            at com.mysql.jdbc.Connection.execSQL(Connection.java:2994)
            at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:936)
            at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:773)
            at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:168)This is my code thats trying to write that binary file:
    public class StoreData {
        private static Log log = LogFactory.getLog(StoreData.class);
        private static final String INSERT_BLOB = "Insert into videos.files (id, owner_id, desc, file_blob)" +
                                                  " values(1, 1, 'uploaded file from user', ?)";
        public void WriteData(VideoUploadForm myForm){
            log.info("Writing file to database");
            Connection conn = ConnectionUtil.getConnection();
         PreparedStatement stmt = null;
            // Process the FormFile
            FormFile myFile = myForm.getTheFile();
            byte[] bytes = null;
            try{
                bytes = myFile.getFileData();
            }catch(IOException ie){
                log.error("Upload File not Found");
                ie.printStackTrace();
            InputStream is = new ByteArrayInputStream(bytes);
            try {
                stmt = conn.prepareStatement(INSERT_BLOB);
                stmt.setBinaryStream(1,is,bytes.length);
                stmt.execute();
                stmt.close();
            }catch (Exception e) {
                log.error("Error writing data to file:");
                e.printStackTrace();
         } finally {
             ConnectionUtil.closeStatement(stmt);
             ConnectionUtil.closeConnection(conn);
    }Looking for some help here.....

  • How to read a file with both text and binary data?

    For text data I use a BufferedReader,
    for binary data I use a DataInputStream.
    Since readLine is deprecated in DataInputStream, how can I read in a proper way a file that contains some lines of text followed by some binary data.
    Is there a way to do this without writing a new 'readLine' for DataInputStream (that has to take into account the different newlines for Unix en other OS's)?

    sorry about that ^
    NEW STRING str
    WHILE there is stuff in the file DO
        getByte()
        IF reading a string THEN
            WHILE byte is not a return character DO
                convert the byte to character/string
                append char to str
            WEND
        ELSE IF reading raw data THEN
            parse raw data
            do stuff with it
        END IF
    WEND

  • Example using setcontenttype to write binary data?

    Hi there,
    I'm having trouble getting my jsp to read a binary file and send the response to an http client.
    I'm not sure what it could be between the getWriter, getOutputStream, setcontenttype, and other methods involved.
    Can anyone provide and/or point me to a simple example where a binary file is opened, read, and the contents sent back to a web-browser?
    Thanks!

    First, I would not recommend using JSP, but use servlets instead. If you have any newlines in the page like after <%@ page directives, you are can't write binary data. So you have to make all your page directives and everything have no newlines, making it ugly to read.
    Second, use getOutputStream() to write to...
    request.setContentType("application/octet-stream"); // or actual file mime type
    request.setHeader("Content-Length", theFileSizeInBytes);
    request.setHeader("Content-Disposition", "attachment; filename=" + theFileName); // if should do save as
    OutputStream os = response.getOutputStream();
    ...

Maybe you are looking for

  • Change in Word folder behavior since Mavericks update

    Since updating to Mavericks it appears Microsoft Word 2011 is having trouble with default folders. The location set in Preferences - File Locations - Documents seems to be ignored. Further, any Save As bounces back to Documents rather than to the doc

  • How can I select and delete messages without T'bird opening each one as it is selected?

    Well, that says it.... if I select a message, say, to delete it because the subject line says "If you open this message, your computer will be instantly infected with every known malware" - - woops! the Thunderbird setup just opened it. -- I need to

  • OS X lost password on used IMac

    I've purchased a used IMac from a friend.  The windows Vista side boots and runs properly.  However, when booting to OS X (via bootcamp) i'm foiled by a password screen setup by the friend's son who is uncooperative and lost.  Is there a process to r

  • How do I scan a doc then edit.

    How do I scan a doc then edit.

  • Graphical layout editor for screens

    I am using SAP gui 6.40 and have installed patch level 23. Still i cannot see the graphical layout editor in se51 and only alphanumeric editor is available (the flag for graphical layout editor in utilities> settings is checked). any hints?? regards,