how to optimize ZipOutputStream to use less ram memory 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) {             }         }     }
Streaming large files in a java servlet 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 would like my Dock to show only the windows of the current workspace. Especially in the little preview window. I find it very confusing to jump around workspaces when trying to find the right window. What are the biggest differences between Reversal Rings, Extension Tubes and Macro Lenses? As far as I understand all three options help you do macro photography but are their other reasons for having the three different items? I figured reversal rings and extension tubes were just for the low cost but with additional more expensive features being added to the two options it seems there may be certain situations for each type? What are their biggest differences and advantages over each other?   Are there situations where you would have one over the other? Do all three options have the same "wafer thin" depth of field?  Do they all suffer from the same light loss? Do any of them affect your photos more negatively than the others? Can I achieve the same magnification with rings and tubes that I can with proper lenses? Would you ever combine these options together or would there be no need for that?   I ask because I recently bought a cheap extension tube and reversal ring and I'm trying to get a better overall understanding of each. I tend to use the extension tube a lot more, because I can put it on my 70-200 and have a workable distance between subject and lens.  This photo was taken with 49mm of extension tube on the 70-200 I believe which may be greater than 1:1. Would it be sharper with a macro lens?       on 500px Is it safe to put a clothes washer outdoors? How many ways can you divide $9$ students into three unlabeled teams where one team contains $4$ people, one contains $3$ people and the last contains $2$ people? Unlabeled, meaning that groups with abc = bca = cba, etc  I understand how to do this if the teams are labeled:  $$\frac{9!}{4!3!2!}$$  But there is a term missing in the denominator when the teams are unlabeled and I'm having difficulty understanding how to calculate how many ways the teams can be organized.  There are $3!$ ways to organize the same first group of $3$, $4!$ ways to organize the same second group of $4$ and $2!$ ways to organize the last group of $2$. Why wouldn't you multiply $3!4!2!$ in the denominator?   For instance:  (ABC, DEFG) = (ABC, DEGF)  = (ABC, DFEG) = (ACB, DFGE), etc I can see by manipulating the expression why $\mathbb{E}X$ works out to be $\int_0^\infty 1-F(x)\,dx$, where $F$ is the distribution function of $X$, but what is an intuitive explanation for why that is true? If at each point we sum the probability $\mathbb{P}(X&gt;x)$, why should we end up with the expectation?  Thanks From official :     Due to a head injury, Cyclops is unable to shut off his optic blasts   at will and must therefore wear ruby quartz lenses to block the beams.   From the same page:     Cyclops possesses the mutant ability to project a beam of heatless   ruby-colored concussive force from his eyes, which act as   inter-dimensional apertures between this universe and another.   When his eyes are always blocked by ruby-colored beam of concussive force, how does he see? Overriding !important style Title pretty much sums it up.  The external style sheet has the following code:  td.EvenRow a {   display: none !important; }   I have tried using:  element.style.display = "inline";   and  element.style.display = "inline !important";   but neither works. Is it possible to override an !important style using javascript.  This is for a greasemonkey extension, if that makes a difference. How to import all files of a folder at once? How do I add this extra partition to my installed Ubuntu system? I started installing Ubuntu by watching a video tutorial about doing a disk partition installation, for that, inside Windows' 7 own disk partitioning tool. After a defrag I cut 100GB that I pretended to use on my Ubuntu installation for a little try out, now, while installing, I never really chose where I wanted Ubuntu to be installed, so I guess it just made a partition by itself of the minimum that the installation tells you it needs.  How can I now give the other 92 GB I had left apart only for that task?  Here's what my partitions look like now.     Here's a df:    And here's the GParted tool un ubuntu: Can you link external USB hard drives in a RAID-style system? Is (rest) mass conserved in special relativity? I don't understand why it is said that the (rest) mass of a system is not conserved in relativity. I mean, the momentum of a system is conserved (i.e.: it remains constant in a frame of reference without any external influence). Also the energy of a system is conserved in relativity: it doesn't change without any external agency  and the (rest) mass of a system is just  $$m^2=E^2-p^2$$  $E$ is constant, $p$ is constant, how can $m$ change?  For example, entropy is not conserved in a system, that means that the entropy of the system will increase spontaneously with time, which is really the case. But, is this true for mass?   here is the problem from Griffiths and exact solution as given in the Griffiths,  Two lumps of clay, each of rest mass $m$, collide head-on at $3c/5$ and they stick together. Question: what is the rest mass $M$ of the composite lump?  Solution: In this case conservation of momentum is trivial it is zero before and zero after. The energy of each lump prior to the collision is $$mc^2/\sqrt{1-v^2/c^2} =5mc^2/4.$$ The energy of the composite lump after the collision is $Mc^2$ (since its at rest). so the conservation of energy says: $5mc^2/4 + 5mc^2/4 =Mc^2$ and hence $M=5m/2$.  Notice that this is greater than the sum of the initial masses! Mass was not conserved in this collision; kinetic energy was converted into rest energy, so the rest mass increased. How many solutions for an equation with simple restrictions I'm working on an assignment in which I have to count the number of solutions for this particular equation: $$x_1+x_2+x_3+x_4=20$$for non negative integers with $x_1&lt;8 $ and $x_2&lt;6$   I'm aware that this kind of a task isn't that complicated, but I don't get combinatorics in general that well.  So I've tried two following approaches to get this done.  Firstly I tried to substitute the variable x:  $x_1+x_2+x_3+x_4=20 \Leftrightarrow y_1+y_2+y_3+y_4=34$  in which $y_1=x_1+8$ and $y_2=x_2+6$ (casue $x_1=y_1-8$ and $x_2=y_1-6$) Following this approach the total number of possible solutions would be  $${34+3 \choose 3} $$  But I'm not sure if its the right solution.  The second approach is to sum all of the possible values that $x_1$ and $x_2$ could possibly take, also $x_1=0,1,2,3,4,5,6,7$ and $x_2=0,1,2,3,4,5,6$ And then  count all the possibilities for each of the variables $${20 -x_1-x_2+1\choose 1}$$ and sum them together like this: $${21\choose 1}+{20\choose 1}+{19\choose 1}+{18\choose 1}+... $$ and so on...  I'm sure I'll get the correct number with this one, but I'm not feeling like summing all of this possibilities. There's got to be a better, more elegant way to deal with this.  My professor gave me a hint that I should do it using the complement. When A and B are positively related variables, can they have opposite effect on their outcome variable C? A is positively related to B.  C is the outcome of A and B, but the effect of A on C is negative and the effect of B on C is positive.  Can this happen? How to get the result of OnPostExecute() to main activity because AsyncTask is a separate class? What to do to switch to biblatex? Because of the great answers posted around in the site, I'm finally considering to do the switch and move to biblatex. So, the question is what do I have to do?  To give the question some focus, assume that I already have a somewhat largish .bib file and a bunch of documents using natbib for my references. What do I have to change in my existing .bib and .tex files?  And what about coauthors? Would it be reasonably simple to instruct them how to work with the new documents using biblatex? Do they have to install new software/packages as well? Merge files based on matching of first column Object rotate in a strange way today i run into another problem. i dont know how i have done it (probably i clicked sth what i should not click) - anyway - since that moment my objects are behaving totally different when i try to rotate them. the objects are now rotating around the pivot point but they keep their alignment - not sure if i am clear. eg. if u would rotate a plane which is lies flat on the ground it makes the rotation but the faces of the plane would still be up and dont which shouldn't be the case with the "normal" rotation that i know. so i want to understand what i have done (because this kind of rotation could be also usefull sometimes for me) and how can i return it in the case it happens again. Well the question is to solve for $x$ in $$a^x+b^x=c \tag{a,b,c are constants}$$   Well as of me, I tried to put $\ln{}$ on both sides which does not seem to help. Apart from this I don't seem to have any other way to solve it.   I turned to WolframAlpha and the solution which was given was : $$x=\dfrac{-i(2\pi n +\pi)}{\ln{a}-\ln{b}} , {n \in \mathbb{Z}}$$  And if $n=0$ $$x=\dfrac{-i\pi}{\ln{a}-\ln{b}}$$  The only thing I am able to recognize is $e^{i\pi}=1$ ... i guess is used.  Link :   So I see that $x$ is independent of the constant $c$.  So how to solve it? Please help...Thanks!    EDIT - It seems that WolframAlpha is taking $c=0$ as suggested by Donkey_2009. And when i write "Solve for x in a^x + b^x = k" it is not returning anything. So are you guys aware of a method to solve this? Also are you guys aware of any other website/software like WA?    P.S. - Also I see that IF we know the values of $a,b,c$ resulting in something like $2^x+3^x=100$ , then Newton's method is the only method I am aware of that can solve it...  Any other suggestions? If I press the "include alpha-button" in the Mix-Color-Node, I get white borders. Otherwise i've got a perfect alpha but no blue background. A well-known application of the MVT is to prove that any $f: \mathbb{R} \to \mathbb{R}$ with $f'= 0$ is constant. But of course, the MVT relies fundamentally on the properties of $\mathbb{R}$, and in particular does not hold in $\mathbb{Q}$. A standard counter-example is the function $f :\mathbb{Q} \to \mathbb{Q}$ defined by $ f(x)=0 $ if $ x &lt;\sqrt{2}$, and $f(x)=1$ if $ x &gt; \sqrt{2}$, for this function is locally constant. There are several ways of thinking about the difference between $\mathbb{R}$ and $\mathbb{Q}$ : $\mathbb{R}$ is connected while $\mathbb{Q}$ is totally disconnected, closed bounded intervals are compact in $\mathbb{R}$, but not in $\mathbb{Q}$, $\mathbb{R}$ satisfies the least upper bound axiom, $\mathbb{Q}$ does not.   Now, I wanted to see how far one could push this counterexample - is there a function $f :\mathbb{Q} \to \mathbb{Q}$ such that $f'=0$ and $f$ is strictly increasing? Clearly, any slight modification of the usual counterexample where $f$ is locally constant will not do. Also, one can show that if $f$ is uniformly differentiable with derivative zero, it must be constant, even in $\mathbb{Q}$, so I knew I was looking for non-uniformly differentiable but still differentiable $f$.   Eventually, I came up with a construction, albeit not a very explicit one: the idea is that, since $\mathbb{Q}$ is countable, one can enumerate it $q_{1}, q_{2}, q_{3}, \cdots$, and then define $f: \mathbb{Q} \to \mathbb{Q}$ inductively and recursively. If one could define $f$ in such a way that $ \forall \ q_{n} \in \mathbb{Q} \ \exists \ c_{n} \in \mathbb{Q} : \forall \ x \in \mathbb{Q} \ |f(x)-f(q_{n})| \leq c_{n}|x-q_{n}|^2$, and $f$ is strictly increasing, we would be done. The recursive definition essentially defines $f(q_{n+1})$, after having defined $f(q_{1}),f(q_{2}),f(q_{3}), \cdots , f(q_{n})$, in such a way that these inequalities hold and $f$ is strictly increasing, and at each step the new $c_{n}$ is chosen large enough so that these inequalities do not become incompatible at subsequent steps ( I am willing to provide more details of this construction if asked).  Note that, as $n \to \infty$, we must have $c_{n} \to \infty$, so that $f$ is not uniformly differentiable. Interestingly, the only key fact about $\mathbb{Q}$ used in the construction is that it is countable, so in a sense the construction provides a proof that $\mathbb{R}$ is uncountable, given the MVT.  While the construction works, it is not very simple nor explicit, which is perhaps to be expected, and the function must be evaluated point by point in the order given by the enumeration of $\mathbb{Q}$. So I was wondering if anyone else knows or can come up with a simpler construction of a function $ f : \mathbb{Q} \to \mathbb{Q}$ such that $f'=0$ and $f$ is strictly increasing. Any thoughts and ideas are welcome.  Edit: I've asked the same question on MO: