What's the most efficient way to serve a file from a servlet?

I have a servlet that does various different things depending on the needs. Sometimes it dynamically generates content, and sometimes all it does is send a file out, with no alteration.
What is the most efficient way to just send a file?
One option:
OutputStream os = response.getOutputStream();
InputStream is = new FileInputStream(...)
(send all the bytes from is to os, the regular way using a buffer)Another option is to say:
RequestDispatcher rd = response.getRequestDispatcher(fileName);
rd.forward();Any other options? What's the prefered way of doing this?
I know the rule of "don't optimize too early" but this is a situation where we need to get the maximum amount of files served with the hardware we have, and it's going to be a lot of static files, so efficiency is important.
Thanks

Ok, that's what I thought. It would be nice if there were a "response.sendStream(InputStream input)" method in the ServletResponse class. Even nicer would be a sendFile or sendChannel or something. This is probably a common usage and it's a place where the container has many opportunities for optimization. For example, it could call the operating systems send_file kernel call so the entire transfer would be done directly from the disk controller to the ether card (on systems that support that).
For now I'll just do my own buffered copy.

Similar Messages

  • What is the most efficient way to use Remove Grain from After Effects on large Premiere Pro project?

    I've tried to use Dynamic Linking both ways but it doesn't the effects don't appear no matter how dramatic I make them. Why couldn't there just be Remove Grain in Premiere Pro so I wouldn't have to go through the headache of figuring this out. I've tried importing the Premiere Pro project into After effects where everything comes up and, since there's so many files, it doesn't seam feasibly or convenient at all. Trying Dynamic Link vice versa didn't lend results either. What can I do??? Projects range from about a half hour to an hour and a half. Thank you.

    The situations are well lit; it might be lack of knowledge on the camera settings itself.
    Sort that and your workflow issue dissapears instantly.
    There's nothing more efficient?
    Yep...read above... but ...any Plugin. eg Neat Video... will take long processing time.
    Fixing grain..actually "noise"...is always an image  degrading process as well.  It blurs!

  • What is the most efficient way to have full access to the front panel on RT Labview?

    I have a RT machine that needs to do its job and also port the front panel to an external machine over the network. What is the most efficient way to do it? Using as little of the RT time as possible but providing full functionality to the RT front panel.
    So far I have been using it directly from Labview - running the VI on a remote (RT) and have the front panel on local Labview (WINDOWS). I know I can do it with also through WWW (not very happy with that though).
    LV2009 SP1.
    Thanks

    Running a compiled executable on the RT target, rather than running it within the development environment, is probably slightly more efficient but limits you to the web interface.  If you're running within the LabVIEW environment, I doubt there's a noticeable difference in efficiency from the RT perspective between the web server and the LabVIEW front panel, although that's mostly a guess (I would expect the RT system to send identical data in each case, once the front panel is loaded).  Those are your only options in modern LabVIEW versions.  In LabVIEW 7.1 you could build an executable that acted as the front panel for an RT system, but that feature does not exist in recent versions.  However, a quick search turned up this document with code to approximately duplicate that behavior, perhaps it will work for you?

  • What is the most efficient way to post several stories to multiple html pages

    What is the most efficient way to post five stories to multiple html pages?
    Currently they are all html files saved in DW with some divs sharing content and other divs are unique.
    I've experimented with saving stories as library items and dropping into other html but wondered if there is a more efficient or dynamic process.

    Server-Side Includes.
    http://forums.adobe.com/message/2112460#2112460
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    http://alt-web.com/
    http://twitter.com/altweb

  • I am giving my old MacBook Air to my granddaughter.  What is the most efficient way to erase all the data on it?

    I am giving my old MacBook Air to my granddaughter.  What is the most efficient way to erase the data?

    You have two options.....
    One is to do a clean reinstall of your OS - if you still have the USB installer that came with your Macbook Air...
    The second option is to create a new user (your granddaugher's name).....Deauthorize your Macbook Air from your Itunes and Appstore.....
    Restart your Macbook after you've created your granddaughter's user name, login under your granddaughter's username and delete your username.
    Search your Macbook for your old files and delete them.....
    Good luck...

  • What is the most efficient way to convert a static site to a responsive site using Dreamweaver?

    I need to convert an old site made in Dreamweaver to be responsive to any monitor size. What is the most efficient way to do this?

    Depending on what you have to work with and how it was coded, it might be doable and then again not.  Suffice it to say, there are no magic buttons that will do this for you. Also consider that mobile & tablet users interact differently with their web devices. So your navigation & forms must be finger friendly.  Also images & content must make mobile users happy without killing their dataplans.  There's a lot of planning that goes into making a good Responsive Web site.
    Nancy O.

  • What is the most efficient way to turn an array of 16 bit unsigned integers into an ASCII string such that...?

    What is the most efficient way to turn a one dimensional array of 16 bit unsigned integers into an ASCII string such that the low byte of the integer is first, then the high byte, then two bytes of hex "00" (that is to say, two null characters in a row)?
    My method seems somewhat ad hoc. I take the number, split it, then interleave it with 2 arrays of 4095 bytes. Easy enough, but it depends on all of these files being exactly 16380 bytes, which theoretically they should be.
    The size of the array is known. However, if it were not, what would be the best method?
    (And yes, I am trying to read in a file format from another program)

    My method:
    Attachments:
    word_array_to_weird_string.vi ‏18 KB

  • Moving content from iMovie to iMovie - what's the most efficient way?

    If I edit and create movies in iMovie08 on one iMac and I want to transfer the content to iMovie08 another iMac 200 miles away , what's the most efficient way? I prefer not to burn DVDs, because I want to do further work on the movies on the second iMac's iMovie (so I can share them with iTunes and sync them with Apple TV).

    >PDPageAddCosContents(destPage, PDPageGetCosContents(srcPage));
    Does this method (PDPageGetCosContent) exist? It would be easy enough
    to create, but I don't see it in the document.
    More seriously, I have a vague memory that it is a Really Bad Thing to
    share the same Contents objects between multiple pages. Maybe
    something to do with page deletion, can't remember.
    >PDPageAddCosResource(destPage, PDPageGetCosResources(srcPage));
    These two methods are not symmetric, and PDPageAddCosResource doesn't
    work that way, sadly...
    Aandi Inston

  • What is the most efficient way to compare two Lists?

    List A{itemId,itemName} [1,xyz] [9,iyk] [4,iuo] .......
    List B{itemId,item price} [2,999] [9,888] [1, 444].......
    Assume A will be a much larger list than B
    I am trying to find all the items with same itemiId. what would be the most efficient way to do that?
    Thanks!

    Tinkerbell. wrote:
    BigDaddyLoveHandles wrote:
    You wrote:
    Can we assume that an itemId only occurs once in each list? You're the one making claims and assumptions, not me.No in #4 I asked the OP to verify an assumption.An assumption that couldn't possibly be true. Why are you wasting our time?

  • What's the most efficient way to transfer to personal domain?

    I've been using the cumbersome .Mac address and have spent a lot of time optimizing the site, having also purchased a domain name (which I'll switch to), which is currently masked and forwarded. So what's the most smooth way of using the personal domain without losing all the strides I've made to get bumped up in the rankings? Thanks in advance for your suggestions. www.RedCottageInc.com (that's my future personal domain!)

    I'm saying that you give Google the .Mac URL to get to your sitemap but use the registered domain name for normal access.
    You are promoting your site with www.RedCottageInc.com but, because it is masked, Google needs your web.mac address to access the verification file and the sitemap so that it can spider your site.
    You normally upload your sitemap as "sitemap.xml". You can test its accessibility by entering
    http://web.mac.com/username/WebSiteName/Sitemap.xml in your browser.
    Google needs this URL to get to the sitemap - visitors will use www.RedCottageInc.com.
    Google wants to get to the verification file and the sitemap but your website visitors don't.
    I guess all this is confusing if you haven't done it before and I don't know that I am explaining it very well. The best way to get it is to go through all the steps of creating the verification file and sitemap, uploading them to your site folder and adding and verifying in your Google control panel.
    Here are the relevant Google pages...
    Guidelines...
    http://www.google.com/support/webmasters/bin/answer.py?answer=35769
    Add URL to Google...
    http://www.google.com/addurl/?continue=/addurl
    Verification file....
    http://www.google.com/support/webmasters/bin/answer.py?answer=35658&query=html+f ile&topic=&type=
    Sitemap...
    http://www.google.com/support/webmasters/bin/answer.py?answer=34657&ctx=sibling

  • What is the most efficient way of passing large amounts of data through several subVIs?

    I am acquiring data at a rate of once every 30mS. This data is sorted into clusters with relevant information being grouped together. These clusters are then added to a queue. I have a cluster of queue references to keep track of all the queues. I pass this cluster around to the various sub VIs where I dequeue the data. Is this the most efficient way of moving the data around? I could also use "Obtain Queue" and the queue name to create the reference whenever I need it.
    Or would it be more efficient to create one large cluster which I pass around? Then I can use unbundle by index to pick off the values I need. This large cluster can have all the values individually or it co
    uld be composed of the previously mentioned clusters (ie. a large cluster of clusters).

    > I am acquiring data at a rate of once every 30mS. This data is sorted
    > into clusters with relevant information being grouped together. These
    > clusters are then added to a queue. I have a cluster of queue
    > references to keep track of all the queues. I pass this cluster
    > around to the various sub VIs where I dequeue the data. Is this the
    > most efficient way of moving the data around? I could also use
    > "Obtain Queue" and the queue name to create the reference whenever I
    > need it.
    > Or would it be more efficient to create one large cluster which I pass
    > around? Then I can use unbundle by index to pick off the values I
    > need. This large cluster can have all the values individually or it
    > could be composed of the previously mentioned clusters (i
    e. a large
    > cluster of clusters).
    It sounds pretty good the way you have it. In general, you want to sort
    these into groups that make sense to you. Then if there is a
    performance problem, you can arrange them so that it is a bit better for
    the computer, but lets face it, our performance counts too. Anyway,
    this generally means a smallish number of groups with a reasonable
    number of references or objects in them. If you need to group them into
    one to pass somewhere, bundle the clusters together and unbundle them on
    the other side to minimize the connectors needed. Since the references
    are four bytes, you don't need to worry about the performance of moving
    these around anyway.
    Greg McKaskle

  • SQL query with multiple tables - what is the most efficient way?

    Hello I am learning PL/SQL. I have a simple procedure where I need to find number of employees and departments per location as per user input of location_id.
    I have 3 Tables:
    LOCATIONS
    location_id (pk)
    location_name
    DEPARTMENTS
    department_id (pk)
    location_id (fk)
    department_name
    EMPLOYEES
    employee_id (pk)
    department_id (fk)
    employee_name
    1 Location can have 0-MANY Departments
    1 Employee has 1 Department
    Here is the query I came up with for PL/SQL procedure:
    /*Ecount, Dcount are NUMBER variables */
    SELECT SUM (EmployeeCount), COUNT(DepartmentNumber)
         INTO Ecount, Dcount
         FROM     
         (SELECT COUNT(employee_id) EmployeeCount, department_id DepartmentNumber
              FROM employees
              GROUP BY department_id
              HAVING department_id IN
                        (SELECT department_id
                        FROM departments
                        WHERE location_id = userInput));
    I do get the correct result, but I am just wondering if my query is on the right track and if there is a more "efficient" way of doing this.
    Thanks in advance for helping a newbie out.

    Hi,
    Welcome to the forum!
    Something like this will be more efficient:
    SELECT    COUNT (employee_id)               AS ECount
    ,       COUNT (DISTINCT department_id)     AS DCount
    FROM       employees
    WHERE       department_id IN (     SELECT     department_id
                        FROM      departments
                        WHERE      location_id = :userInput
    ;You should also try a join instead of the IN subquery.
    For efficiency, do only the things you need to do.
    For example, you don't need a count of employees in each department, so don't compute one. That means you won't need the in-line view, so don't have one.
    You don't need PL/SQL for this job, so don't use PL/SQL if you don't have to. (I realize this question was out of context, so you may have good reasons for doing this in PL/SQL.)
    Do all filtering as early as possible. Don't waste effort computing things that won't be used .
    A particular example of this is: Never use a HAVING clause when you can use a WHERE clause. What's the difference between a WHERE clause and a HAVING clause? The WHERE clause is applied before aggregate functions are computed, and the HAVING clause is applied after; there's no other difference. Therefore, if the HAVING clause isn't referencing an aggregate function, it could be done in a WHERE clause instead.

  • WHAT IS THE MOST EFFICIENT WAY OF ORGANISING DOCUMENT FILING ?

    I know this sounds dumb, but I am flummoxed about how to organise filing of folders on my Mac. In the real world filing is easy but computers seem to make it completely different & a nightmare.
    I have ten years worth of using various macs all copied onto the latest one & now occupying about 230 Gigabytes. There are loads of duplicated files and repeated backups from all those years just sitting around taking up space & making it impossible to find anything.
    Obviously I was careless about filing right from the start, not realising what a mess it would get into.
    In the real world you can just clean up an untidy mess and make it tidy, organised and easy to find things. But in the real world you dont have an electronic lunatic duplicating everthing all the time. With over a million files to look at & sort it is simply impossible to do what you would do in the real world.
    One obvious solution is just to archive it and start again. But this time I would like to know how to stop this happening again and what is the best 'system' or way of organising files to stop it all becoming a total mess again.
    What seems to happen is that my good intentions of having about ten folders on my desktop to cover ten areas of activity naturallly degraded as when you have a busy day you collect all sorts of things on the desktop outside of those folders which you want to just leave on the desktop to deal with and complete another day.
    This process happens every day and so when you then clean up the desktop you just bung all those files in the basic ten folders. But that just means you transfer the mess from the desktop into the ten basic folders and the same process just gets endlessly repeated all the way down through each hierarchical layer of the folders.
    This is obviously a problem everyone has, and some bright spark must have worked out a way of preventing this from happening.
    i.e. someone must have worked out the best way of organising a filing system on a Mac.
    And part of this problem is illustrated by email which I have no idea how to stop getting bigger & bigger.
    The only solution I can think of is to archive my whole desktop on an external disk and start all over again from the begining by setting up a brand new account. But while this would work to start off with, unless I can work out some way of doing things better, it will also eventually become a horrible, cluttered mess.
    Has anyone got any ideaas about how to deal with this problem. It must be a problem for everyone really ?

    Well, there are two sides to this. The first is obviously the organizing of your files, which is something that you really have to work out your own solution for. I don't know what your ten folders are called, but it seems that that's not working for you as a way to keep things managed on a daily basis. What kind of files are these - documents (eg Word files), photos, something else? Do they all need to be filed in folders? (If they're images, there are better ways to manage them - eg iPhoto). Do they all even need to  be kept?
    The other side to this is retrieval. We keep things organized so that we can easily retrieve them. However, the advantage of a computer-based system, above a paper filing system, is that you can have multiple ways of getting to information without having to change the way the files are stored. For example, the Finder can store searches as Smart Folders, meanings that you can search documents for "Tax Return" and store the results in a sidebar shortcut. Any documents containing that text (whether in the title or in the document itself, your choice) will automatically be displayed in that "folder" (although you're not moving files, you're simply displaying the result of a search).
    Similarly, tags in 10.9 Mavericks are designed to let you add keywords to files (such as "Urgent", "Pet Information", "Household", "Financial", and so on), and documents tagged this way are automatically shown collected in the sidebar.
    Email services are moving in the same direction. You *can* spend a period of time every day manually filing email into mailboxes you've created to organize them, but a more efficient method can be to leave them all in one folder (ie, the inbox), tag them appropriately, and then display the tagged results as folders (this is what Gmail does with labels), or search for specific criteria (show me all mail from Bob with attachments, show me all mail that includes the phrase "Project Werewolf".
    If you can figure out a smart retrieval system that works for you, I would recommend that over the manual organization which is currently causing you frustrations. Do some basic organizing, sure - you don't want everything in one huge folder - but don't forget there are tools which are there to help you find things quickly.
    Matt

  • What is the most efficient way to run internet explorer on a mac?

    I have to use I.E. for school along with Outlook.  I run windows for mac and am looking for the cheapest and least invasive way to do so.

    CSS731 wrote:
    Specifically I cannot attach files such as students grades or send requests to our photocopy center.  I works great on a pc but won't work on a mac.  Most at my institution thumb their noses at macs and I have been told directly they will not support mac or OSX.  I have tried using firefox but have been told by my colleagues that IE is the only browser that works.
    What you are running into is unfortunately rather common in business, education, and government. What happened is that your school computerized their operations in the late 1990s to early 2000s, when Internet Explorer on Windows XP was the most common web browser. Websites were coded to take advantage of technologies that are unique to IE. Once all these institutions and businesses finished their work, they thought they were done and they moved on.
    But in the time since then, the world changed around them. The Web moved towards "standards compliance," which means writing web sites for the CSS3 and HTML5 standards. Not for old Microsoft-only Internet Explorer features. If a web site is standards compliant, it will work on any browser that is also standards compliant. That would include every popular browser today: Apple Safari, Mozilla Firefox, and Google Chrome. (As well as the latest Internet Explorer for Windows, which is much better than it used to be.)
    Standards compliance was a wonderful revolution, because it meant we could use any browser. It also paved the way for the iOS and Android mobile device boom, since they need to use mobile web browsers and those are not Internet Explorer.
    The big problem is that your institution, like many others in education, business, and government, either doesn't want to upgrade their systems or doesn't have the budget. The system they built in 1996 or 2002 is being maintained, but it isn't being modernized. Therefore, it is not standards compliant. That's why it doesn't work with Firefox or Safari.
    I am sure that both you and they have noticed that they have fallen behind, because it's very easy to show this. If you go to any modern web site...Facebook, Twitter, Flickr, Yahoo, Dropbox, every photo sharing site, every web forum, etc. it is extremely easy to upload attachments no matter what web browser you use.
    Of course, they'll get very defensive if you try to tell them that their systems are totally out of date and any browser should be able to upload attachments. Even if that's true, they may not be able to overhaul their systems any time soon. Maybe they would like to, but they can't get the funding. The problem for them is that more and more devices are being used on their network which don't have Internet Explorer, like Macs, phones, and tablets, and it's revealing the limitations of their system.
    That's the situation. It won't be easy to fix because it requires that the school's systems be modernized. But they really need to be modernized, because as we saw, attachments are no problem on multiple browsers on all the other web sites we use every day.
    If they could update their systems, the benefits would be significant. If their web site became standards compliant, it would automatically support smartphones, tablets, and Mac web browsers with probably very little extra work.

  • What is the most efficient way of converting relatively large program to pervious version?

    I am trying to convert 8.5 labview program to 8.2 version.  When I do that it creates many more subfolders with VIs that are not converted.
    What is the best way to do this?  I tried the mass compile but converting the high level  program creates many folders that links to other areas?
    Am I missing anything?
    Thanks for any help.
    Chetna 

    Hi Chetna,
    How are you confirming that the VIs saved in the sub-folders after conversion have not been converted to a previous version? 
    If you open the VI at the top of the hierarchy and 'Save for Previous Version...' it saves the open VI and all it's depencies for the chosen version. The reason you see all the sub-folders is because the relative path between VIs is maintained.
    This KnowledgeBase article: Can I Save VIs in My Current LabVIEW for Use in a Previous Version? describes this process.
    There is also a Community Example: Programmatically Save VIs for Previous Version that could also save time if you have a lot of VIs to convert.
    I hope this helps!
    Tanya V
    National Instruments
    LabVIEW Platform Product Support Engineer

Maybe you are looking for

  • How to get multiple measures in measure hierarchy in Essbase Studio

    Hi All, Previously we are using one measure column which will gives the count.Now the current requirement is to get multiple measures in measure hierarchy. For Example Measure Count SalesCount(count*Sales/10) CustomerCount(count*customer/10) In the f

  • How do i turn off the find my phone

    i have a iphone 6 64 gb gold. i also have the same phone in the grey.i want to sell my gold iphone but i dont know how to turn off the "find my phone program. help?

  • What do I need to view Adobe TV on a mac

    This has probably been posted somewhere else but I am unable to find the thread. I cannot seem to view Adobe TV tutorials on my iMac with Safari. Youtube tutorials work fine, but not all the tutorials are available on Youtube. I have posted this on A

  • Can a netui:template include another template?

    I have a case where I want to have 2 different templates (myTemplate.jsp and myTemplate2.jsp). Both use almost all of the exact same code, with a minor exception. I didn't want to have to just copy one and modify the one section that is different, b/

  • Help, Dreamweavers FTP hangs and crashes my computer -

    Hi, since a while Dreamweavers FTP functions won't work properly any more - lots of timeouts, incomplete uploads and syncs , crashes - that with any server I'm connecting to. Does anybody know what could have caused this change of mind of the before