I am using this code to download zip file containing jasper reports. How can I use less memory on my Servlet? Can I use disk space instead of memory? or is there any other way so that my server will not give me an error saying "out of memory" if many users will try to download zip file at the same time or if the zip file size is huge.     public void zipJasper(List&lt;JasperPrint&gt; print) {         ByteArrayOutputStream baos = new ByteArrayOutputStream();         ZipOutputStream out = new ZipOutputStream(baos);         try {             int k = 1;             for (int j = 0; j &lt;= print.size(); ++j) {                 byte[] buffer = new byte[1024];                 byte[] pdfAsBytes = JasperExportManager.exportReportToPdf(print.get(j));                 ByteArrayInputStream fis = new ByteArrayInputStream(pdfAsBytes);                 zipfile.putNextEntry(new ZipEntry(print.get(j).getName() + ".pdf"));                 int length;                 while ((length = fis.read(buffer, 0, 1024)) &gt; 0) {                     zipfile.write(buffer, 0, length);                 }                 //    zipfile.closeEntry();                 // close the InputStream                 fis.close();             }             //   zipfile.close();         } catch (JRException ex) {             log("An error occured", ex);         } catch (IOException ex) {             log("An error occured", ex);         } finally {             try {                 // Flush the stream                 zipfile.flush();             } catch (Exception e) {             }             try {                 // Close the stream                 zipfile.close();             } catch (Exception e) {             }         }     }
I am building a java server that needs to scale. One of the servlets will be serving images stored in Amazon S3.  Recently under load, I ran out of memory in my VM and it was after I added the code to serve the images so I'm pretty sure that streaming larger servlet responses is causing my troubles.  My question is : is there any best practice in how to code a java servlet to stream a large (>200k) response back to a browser when read from a database or other cloud storage?  I've considered writing the file to a local temp drive and then spawning another thread to handle the streaming so that the tomcat servlet thread can be re-used. This seems like it would be io heavy.  Any thoughts would be appreciated. Thanks.
I am using a tikzpicture for plotting. the values I want to plot are typical (X,Y) pairs. The x-value is an uninteresting id-value. I want to order the bins ascending/descending according to the y-value, but how do I do that? The figure seems to automatically take the x-values for ordering, how can I override that? (I am not particularly fixed to tikzpicture - its just the first thing that actually worked and displayed the plot....) Following minimal-working example, how could I achieve a reordering according to the y-value?  \documentclass{article} \usepackage[english]{babel} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{relsize} \usepackage{times} \usepackage{url} \usepackage{latexsym} \usepackage{graphicx} \usepackage{colortbl} \usepackage{color} \usepackage{caption} \usepackage{pgfplots, pgfplotstable} \usetikzlibrary{arrows} \usepackage{amsmath} \usepackage{multirow} \usepackage{booktabs}  \usepackage{filecontents} \definecolor{OgAns}{rgb}{0, 0.8, 0.4}  \begin{filecontents}{testdata.dat} 1   30 2   44 4   26 3   39 \end{filecontents}  \begin{document} \begin{figure} \begin{tikzpicture}         \begin{axis}[                ybar stacked,             ymin=0,             ymax=100,             bar width=5pt,             legend style={at={(0.35, -0.4)},anchor=south west},             legend columns=-1                       ]           \addplot[ybar,fill=OgAns]  file {testdata.dat};          \end{axis}     \end{tikzpicture} \end{figure}   \end{document} Why does everyone tell me writing code like this is a bad practice?  if (foo)     Bar();  //or  for(int i = 0 i &lt; count; i++)     Bar(i);   My biggest argument for omitting the curly braces is that it can sometimes be twice as many lines with them. For example, here is some code to paint a glow effect for a label in C#.  using (Brush br = new SolidBrush(Color.FromArgb(15, GlowColor))) {     for (int x = 0; x &lt;= GlowAmount; x++)     {         for (int y = 0; y &lt;= GlowAmount; y++)         {             g.DrawString(Text, this.Font, br, new Point(IconOffset + x, y));         }      }  }  //versus using (Brush br = new SolidBrush(Color.FromArgb(15, GlowColor)))     for (int x = 0; x &lt;= GlowAmount; x++)         for (int y = 0; y &lt;= GlowAmount; y++)             g.DrawString(Text, this.Font, br, new Point(IconOffset + x, y));   You can also get the added benefit of chaining usings together without having to indent a million times.  using (Graphics g = Graphics.FromImage(bmp)) {     using (Brush brush = new SolidBrush(backgroundColor))     {         using (Pen pen = new Pen(Color.FromArgb(penColor)))         {             //do lots of work         }     }  } //versus using (Graphics g = Graphics.FromImage(bmp)) using (Brush brush = new SolidBrush(backgroundColor)) using (Pen pen = new Pen(Color.FromArgb(penColor))) {     //do lots of work }     The most common argument for curly braces revolves around maintance programming, and the problems that would ensue by inserting code between the original if statement and its intended result:  if (foo)     Bar();     Biz();     Questions:   Is it wrong to want to use the more compact syntax which the language offers? The people that design these languages are smart, I can't imagine they would put a feature which is always bad to use. Should we or Shouldn't we write code so the lowest common denominator can understand and have no problems working with it?  Is there another argument that I'm missing? If $x_1,x_2,\ldots,x_n$ are real numbers larger than $1$, prove that $$\dfrac{1}{1+x_1}+\dfrac{1}{1+x_2}+\cdots+\dfrac{1}{1+x_n} \geq \dfrac{n}{\sqrt[n]{x_1x_2\cdots x_n}+1}$$   Attempt  AM-GM doesn't work here since we will get an upper bound. I don't see Cauchy-Schwarz working either. Thus, I think a substitution might work, but I am unsure of which one to use. How do I get the size of a directory on the command line? I tried to obtain the size of a directory (containing directories and sub directories) by using the ls command with option l. It seems to work for files (ls -l file name), but if I try to get the size of a directory (for instance, ls -l /home), I get only 4096 bytes, although altogether it is much bigger. Asymptotic complexity of .NET collection classes I'm searching for a word to indicate something that was current at some time in the past, but not necessarily now.    For example:       The doctor's report of June 2008 set forth the patient's ?{then-current} complaints. Overdispersion and Underdispersion in Negative Binomial/Poisson Regression I was performing a Poisson regression in SAS and found that the Pearson chi-squared value divided by the degrees of freedom was around 5, indicating significant overdispersion. So, I fit a negative binomial model with proc genmod and found the Pearson chi-squared value divided by the degrees of freedom is 0.80. Is this now considered to be underdispersed? If so, how does one go about handling this? I have read a lot about overdispersion and believe I know how to handle this but information on how to handle or determine if there is underdispersion is scant. Can anyone assist?  Thanks. Vertical text (not in table) Can a Spring form command be a Map? Cardinality of equivalence relations on N URW-Garamond with mathdesign is typesetting vertical double-quote as vertical double-quote I just started using URW-Garamond with mathdesign, and it's typesetting straight double-quote character as a straight double-quote rather than a right double-quote.  How can I fix this?  That is, when I put this in my header:  \usepackage[T1]{fontenc} \usepackage[urw-garamond]{mathdesign}   I get a nice Garamond in my output, but " in my input file produces a Garamond version of the same character in the output.  If I use two single-quotes instead, it comes out properly as a double right-quote.  I could switch to typing '' or set up a macro, but this is undesirable for more than one reason.  Is there any way to use urw-garamond without this non-traditional behavior for "? What exactly is an environment variable? Possible Duplicate:          The  describes the expansion of the $n$th power of the sum $(a+b)$:  $$(a+b)^n = \sum_{k = 0}^n {n\choose k}a^kb^{n-k}$$  In calculus, there is a generalization of the product rule called , which describes the expansion of the $n$th derivative of the product of two functions $f$ and $g$:  $$(fg)^{(n)} = \sum_{k = 0}^n {n\choose k}f^{(k)}g^{(n-k)}$$  It's not difficult to prove using the product rule and induction, what I'm really trying understand here is why the formula is true. Is there a way to prove it using the binomial formula? How are these two formulas related? Is there a combinatorial proof for Leibniz's rule like there is for the ?   I understand this question is a bit vague, but I hope you'll agree that these two formulas look so similar it just feels like there should be some relation between the two. Of course this is not necessarily true, but I'm hoping it's not just a crazy coincidence. I installed nginx a while ago using the ubuntu PPA repository.  Now I want to compile nginx from source so I can compile in and use the geo-ip module.  I know how to compile the new nginx from source.  How can I remove the nginx binary which was installed by the package?  I want to leave all the configs and logs and upstart stuff etc untouched.  I really just want to remove the old binary.  How can I do this? What's the meaning of "be blowed"? I would like to know what's the meaning of "be blowed" in the following text:     'I'm going to smoke' Jenkins said; 'be blowed to Bertie dear.' (Mrs. Smythe had once addressed her husband in the office as 'Bertie dear', and thereforth that had been his name among the staff.) Richard made no answer. When a minute later Jenkins, discreetly directing his puffs to the open window, asked him for the titles of one or two of Zola's novels in English, and their price, he gave the required information without turning round and in a preoccupied tone.   , Arnold Bennett, 1911. How to exclude/delete files only? Is there a way to exclude all files, in all subfolders, and keep the folder structure? align xticks in PGFPlots Should "Applied Cryptography" be capitalized? Is it a proper noun? I'm trying to write a cover letter for a fairly prestigious job, and I'm aiming for (arguably too much) perfection in my cover letter. I don't want to be turned away only because the hiring people though I was too careless with my punctuation and capitalization.  My sentence goes as follows:     I hope to one day go on to complete a Masters degree in Computer Science with a focus in Applied Cryptography.   I've never been great with the technical rules of the English language, despite being a native speaker. What do we lose passing from the reals to the complex numbers? As normed division algebras, when we go from the complex numbers to the quaternions, we lose commutativity. Moving on to the octonions, we lose associativity. Is there some analogous property that we lose moving from the reals to the complex numbers? Some spells, such as Forbiddance, say that under certain circumstances, they last "Until Dispelled".  Other spells, such as Mordenkainen's Private Sanctum, say that under certain circumstances, they become "Permanent".  What is the difference between these two terms?  Does "Permanent" mean that the effect can never be dispelled?