Using a servlet to send binary data

There is a section of our intranet that need to hold documents that have to be available only for a certain group of users. Here's my approach (if you think of a better one, please tell me):
1-all the files are in a directory upper than WWWRoot so that nobody can directly download them
2-there is a servlet that first: authentificate the user with username-password; and then lists all available documents.
3-When one of these docs is clicked, I want my servlet to open the file using filesystem File object and then copy the content of the selected file in the http response body. What object and method should I use to do so? I dont know if I should use FileReader or something else. Dont forget it will not only has to work with text files, but also with binary data files like swf, powerpointpresentation and the like. So I fear that objects such as FileRead will mess special characters up and corrupt data.
What would you advice me? Use FileReader or another object? Or maybe a completly different approach for the problem? And if you want to give me some sample codes, it would be appreciated.
Thx for your help

There is something I dont understand.. its bizarre. Usually I dont understand why a script is not working, but now, I dont understand why a scritp is working..
Here are the codes that copy from a file to the servlet's ouput:
//basic response configurations
response.setContentType( mimeType );
ServletOutputStream out = response.getOutputStream();
//copy a file f to the servlet's output stream
File f = new File( path );
FileInputStream fis= new FileInputStream(f);
int available = fis.available();
byte[] b = new byte[available];
fis.read(b);
out.write( b );
out.flush();
They work fine. What I dont understand is that I tried them with a file of about 5 megs, and they still worked! I expected them to fail because the variable available is of the type int and then it implies that the maximum file size permitted by the algorithm should be 65536 bytes/1024=64 ko... isn't it????

Similar Messages

  • Sending Binary data using ASCII

    Hello All,
    I'm trying to control serial-interface instrument using NI-VISA with a set of ASCII codes, but the instrument reads/sends binary data only. What should I do so that the ASCII codes I send are converted into binary commands for the instrument to read, and that the data I receive is converted back into ASCII?
    Thanks in advance
    M

    Hi M,
    first you should define the words "binary commands/data". Then you should know: ASCII is binary too...
    You may work with an U8 array. You can easily convert strings to U8 arrays and vice-versa!
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Sending Binary Data using HTP package

    Has anyone been successful in using the HTP package and its PUTRAW procedure to send binary data to a browser?
    Example code shows basic idea:
    create or replace
    procedure test_raw as
    output VARCHAR2(20);
    begin
    OWA_UTIL.MIME_HEADER('application/x-gzip', TRUE);
    output := 'Hello World!';
    HTP.PUTRAW(UTL_RAW.CAST_TO_RAW(output));
    HTP.FLUSH;
    end test_raw;
    I receive an empty file when called from the browser.
    What gives?

    I found my answer. I should be using wpg_docload.download_file(BLOB) to "download" a the contents of a BLOB.

  • 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

  • How to send binary data in the message body

    How can we send binary data in the message body that is base64 encoded? below are the requirements
    Mime Header.
    Mime-version: 1.0
    Content-Type: application/octet_stream; name=test
    Content-Transfer-Encoding: Base64
    Submission must be named "test.sub" (lowercase)
    Submission must be base64 mime-encoded
    Submission must be sent in the body of the message (not as an attachment)
    Only one submission per mail message
    No other comments should be put in the body of the mail message (other than the submission)
    I highly appreciate your help. If you can provide few examples, that will be very helpfull.
    Thanks,
    Madan

    Use Message.setContent to set the content, or use Message.setDataHandler with
    a DataHandler constructed with a ByteArrayDataSource. If the content is not
    "naturally" encoded in base64, you can enforce it by setting the Content-Transfer-Encoding
    header to "base64". Any reasonable mail reader won't care what encoding you use, as
    long as the decoded data is correct.

  • Sending binary data over RS232 without conversion to ascii

    I need to send binary data to a PIC without the data being converted to ascii. With the VISA vi's, when I want to send 11111111, it gets converted to a string "255", and is sent as "2","5","5" in ascii.
    How can I send it as one byte?

    r_keller wrote:
    @tbob: I probably shouldnt tell my customer that he's an idiot, and obviously 9 bit addressing/signalling modes seem to be not so uncommon in industry, so ur post does not really contribute to solve the problem.
    Well I wouldn't call my customer an idiot either.  I didn't know he was your customer.  Sorry.  Not every comment posted here is intended to directly solve a problem.  We are a fun loving group, and occasional ribbings take place here.  I still think that trying to use 9 bits over an 8-bit protocol is not a good way to go.  But if it is the only way, then so be it.
    r_keller wrote:
     Does the Mark or Space parity bit add another 10th bit to the command or can i only use either ODD parity/Mark/Space?
    According to the link you attached, the parity bit adds only one more bit.  If the number of bits is set to 8, then the parity is the 9th bit, and you can only use Mark or Space to force that 9th bit to either 1 or 0 respectively.  If you try to use odd or even parity, the protocol will determine the parity and change the bit accordingly, and it may not be the one you intended to send.  The start and stop bits are fixed by the protocol and cannot be used for extra data bits.
    Actually, until I read that article about using Mark and Space, I had no idea at all that sending 9 bits at a time was possible.
    - tbob
    Inventor of the WORM Global

  • Sending binary data as attachment

    Is that possible to send binary ( which is actually fragment of a large file i.e. 100MB ) data as attachment to SOAP message ?
    The complete scenario is below.
    * I have to send a large file around 100MB, to server as a fragment as attachment of SOAP message.
    * It is received at the server and sent as such to another server ( I dont want the user to send data directly to this "another" server, call it as main server ).
    * main server will update the fragment into a stream which remains unclosed until last fragment received.
    * after receiving SOAP message ( which contains the fragment ), main server will repond 'OK' to sub server.
    * If the sub server receives OK, then it will send the next fragment until EOF.
    May be at main server I may need to check whether the file is properly received using some checksum logic.
    I hope I am making sense. I am thinking of using Axis2 ( I am totally newbie to web services). Could someone point me if I miss something ?

    thanks

  • Java proxy to send binary data

    Hi guys,
    I needed a small clarification.
    I'm using java proxy sender and file receiver in a scenario. I want to pick up binary files (i.e. the file could be of any format text,zip,pdf, image etc) using jakarta commons api to connect to ftp and then call the proxy to send this file data via proxy.
    I'm not clear on how this requirement can be achieved or it can be achieved or not.

    Hi Stefan,
    I'm referring to the comments given by Michal in the below blog.
    [How to send any data (even binary) through XI, without using the Integration Repository|How to send any data (even binary) through XI, without using the Integration Repository]

  • Reg : Sending Binary data as output in GP

    Hello ,
    I developed one webdynpro Project it has interactive adobe form ,  in Guided procedures
    created CO for Webdynpro Componet(GP interface) for this form and created GP inerface also.
    But in this callable object the Requestor creates new pdf form.This PDF(means interactive form is taken as binary for pdfsource )  form has binary data.
    *How to send this binary data as output in GP. *
    Please help me out.
    Thanks
    Risha

    thanks

  • Use httpchannel/httpservice combination for binary data

    I have a blazeds proxy configuration set up with my flex application to communicate with a RESTful webservice.
    This webservice is practically an interface to a content management system which has all types of content text and binary(audio,video,images etc) protected by HTTP basic authentication. I had no reason to use Blazeds except for its proxy capabilities to enable HTTP Authentication headers to be sent from the application to the webserver which dont work when sent directly to the server as mentioned.See related post below -
    http://tech.groups.yahoo.com/group/flexcoders/message/136576
    I send the requests through HTTPService from flex through a configured destination and it works well for all data formats supported by HTTPservice. Unfortunately HTTPService does not support binary resultformat for images,audio and video. I am aware that i should use a streaming server for audio and video data but for images I would like to go through the blazeds proxy to the webserver. Loader is the only class which is recommended to be used with images but i am not sure of how to use it with blazeds.
    Is it possible in anyway to achieve what I am trying to?
    Thanks,
    Peeyush

    Try this...
    var b:ByteArray = _dataLoaderHTTPService.lastResult as
    ByteArray;
    b.position = 0;
    trace(b.readObject());
    Bob I.

  • Sending binary data to Nativeprocess (C++)?

    Hello
    I am developing an AIR application, which uses lots of C++ libraries to do number crunching (OCR, taking screenshots,...)
    I need to send somehow BitmapData objects to the C++ app, and i need to do this a lot (like every 1-2 secs.)
    Until now, i've tried 3 methods, all would not work for me:
    1. Save the file to the disk in AIR, start the application, and send the file path as a parameter.
    This method is bad, its terribly slow, because of the lots of disk I/O and compression/decompression of images.
    2. Make a socket server in C++, and use sockets in Actionscript to send files.
    This method is fast, but since i use sockets, the program depends on firewall settings. (i get a "do you allow xxx.exe trough the firewall?" warning too).
    This means, that users with bad firewall settings wont be able to use my application, and it is critical for me, that not tech savvy users can use my app too.
    3. Use NativeProcess.standardinput/standardoutput to send data.
    This method is fast (although i heard, that its slower, than sockets..), but i could not figure out how to send a bytearray. 
    My best try was to receive a Bytearray containing a BitmapData:
    int bsize = width*height*4;
    char* buff = new char[bsize];
    std::cin.read(buff,bsize);
    This did not work either, the received Bytearray was always truncated at approximately its half height.
    Anyone has a good solution? I would love to use sockets, if i can avoid firewall issues somehow. Or a working example how to send a bytearray to C++ would be OK too.
    Thanks.

    the messageString = "00000011"Wild guess: this is supposed to represent the bit pattern of a byte you need to send.
    Don't use Strings at all, use bytes. This byte would be 3.
    Carrying on from the wild guess,messageString = "0000001001101111000001010001001100000011"would becomebyte[] messageBytes = new byte[] {2, 111, 5, 19, 3}

  • Using RDI Interface to send print data to SAP PI

    Hi,
    I have never used the SAPScript Raw Data Interface, but I now have the task to send printing information to SAP PI and
    from there to a print service.
    I see, that I could send the printing documents as IDoc, but is it also possible to call for example a function/program, where I could process the print data and then send it to PI?
    Each different print document needs to have it's own sapscript form to derive the necessary fields of content, right?
    Has anyone an idea, what I could do? Can anyone give me an overview about the possibilities of the RDI interface?
    Thank you very much!
    Michael

    Please check the element "Dealer_code" in your SAP system . Is it a data element or a field? i dont think that is defined in your system.

  • Using JPS/Servlets to send files between 2 servers

    We need to send an XML file that exists on one server to another server. We would like this to be done within the coding of the JSP or servlet without user intervention. Is there any way to use FTP or any other software product to accomplish this?

    One approach you could use is to simply do a HTTP POST from the source server to the target server. The receiving JSP page would accept the XML as a hidden form field and then write it to a file to the local hard drive.

  • Binary data with JMF

    I would like to send plain old binary data using RTP. How can I use the JMF to send binary data without binding it to a codec or media type?

    TouringBMW wrote:
    JMF transports data every 10 seconds, why not use a Webservice? JMF transports data every 10 seconds? That's actually news to me, can you present the source of this information?
    I thought JMF sent out UDP packets as fast as it could / needed to...
    Is this plausible?Not really, no.
    I am looking for a way to stream large content from a server to a webclient to present it. What is the best way? I am using JavaFX as a cliënt.Depends on what kind of content you're talking about. If it's video, that's a different answer than if it's audio, which is different from powerpoint presentations. And your subject calls for an "image server", which doesn't even make sense in terms of "streaming". What does it mean to stream an image?
    Tell us what exactly you're wanting to do, and I'm sure we can come up with some recommendations on how best to do it... :-)

  • Streaming Binary Data

    Hi,
    I would like to send plain old binary data using RTP. How can I use the JMF to send binary data without binding it to a codec or media type?
    Thanks,

    sam8680 wrote:
    I would like to send plain old binary data using RTP. How can I use the JMF to send binary data without binding it to a codec or media type?Is there a particular reason you don't want to use a normal UDP or IP socket for plain old binary data?

Maybe you are looking for

  • Aperture not working after 10.6.5 update

    Hi - i cant start Aperture efter the latest 10.6.5 update from Apple. I get this error message: Process: Aperture [754] Path: /Applications/Aperture.app/Contents/MacOS/Aperture Identifier: com.apple.Aperture Version: ??? (???) Build Info: Aperture-12

  • Project Mangement Tools -- several questions

    I just purchased a Mac Pro and extra internal hard drive and have the following PC compantibility questions: 1. Is Parallels still the best way to run PC product on a Mac (I think I have a Parallels 5 disk somewhere around here.) 2. Is Microsoft Proj

  • Itunes won't import mp3's from my iAudio u2

    Hello, I have an iBook G4 with iTunes 6. I just purchased the iAudio u2 and successfully used it to record a 3 hour file of music that I "lined-in" from my CD player. My next step was going to be to copy the mp3 file to my computer, but I can't get i

  • JBO-25058 exception when running adf:tree component

    Hi, I was trying to prototype an adf:tree which uses eo, vo, and view links as a data model. I am trying to use the vo recursively. Data model consists of : EO: PeggingDataEO VO: TopPeggingDataVO PeggingDataVO View Links: TopToFirstLevelVL (source: T

  • MSI 560 GTX-Ti Twin Frozer II is not recognised by Windows 7

    OK, just finished building my new computer and I should say at the outset that I am not an expert! Unfortunately, Windows 7 does not seem to recognise my MSI card. It is not present in the display adapter in the device manager and when I go to instal