I am looking to convert file input stream for big file (The file is of 100MB) and it is throwing and java.lang.OutOfMemoryError : Java Heap space  import java.io.FileInputStream; import java.io.IOException;  import org.apache.commons.io.IOUtils;  public class TestClass {     public static void main(String args[]) throws IOException     {         //Open the input and out files for the streams         FileInputStream fileInputStream = new FileInputStream("file.pdf");         IOUtils.toByteArray(fileInputStream);     }  }   The actual stack trace is  Exception in thread "main" java.lang.OutOfMemoryError: Java heap space     at org.apache.commons.io.output.ByteArrayOutputStream.toByteArray(ByteArrayOutputStream.java:322)     at org.apache.commons.io.IOUtils.toByteArray(IOUtils.java:463)     at TestClass.main(TestClass.java:12)   I did tried to handle it using the below method   public static byte[] toByteArray(InputStream is) {         if (is == null) {             throw new NullPointerException("The InputStream parameter is null.");         }          ByteArrayOutputStream baos = new ByteArrayOutputStream();         try {             byte[] buffer = new byte[32];             int read;             while ((read = is.read(buffer)) != -1) {                 baos.write(buffer, 0, read);             }             return baos.toByteArray();         } catch (IOException e) {          }   Which then fails with   Exception in thread "main" java.lang.OutOfMemoryError: Java heap space     at java.util.Arrays.copyOf(Arrays.java:2786)     at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:94)     at TestClass.toByteArray(TestClass.java:25)     at TestClass.main(TestClass.java:14)   Is there any way we could handle this !!! Any inputs will be appreciated.  Thanks !!!
I am writing a client-side Swing application (graphical font designer) on Java 5. Recently, I am running into java.lang.OutOfMemoryError: Java heap space error because I am not being conservative on memory usage. The user can open unlimited number of files, and the program keeps the opened objects in the memory. After a quick research I found  and others saying on Windows machine the JVM defaults max heap size as 64MB.  Given this situation, how should I deal with this constraint?  I could increase the max heap size using command line option to java, but that would require figuring out available RAM and writing some launching program or script. Besides, increasing to some finite max does not ultimately get rid of the issue.  I could rewrite some of my code to persist objects to file system frequently (using database is the same thing) to free up the memory. It could work, but it's probably a lot work too.  If you could point me to details of above ideas or some alternatives like automatic virtual memory, extending heap size dynamically, that will be great.
Interprocess communication in .NET I have a core .NET application that needs to spawn an abitrary number of sub processes. These processes need to be able to access some form of state object in the core application.  What is the best technique? I'll be moving a large amount of data between processes (Bitmaps), so it needs to be fast. I am trying to understand the sentence  the mean minimizes the mean squared error.   from wikipedia .  From a previous post  I can see a formal proof which according to the authors prove that the mean minimaze. But my objection on that prove is that is you substitute m with median all the reasoning still stands.  Therefore, I restricted myself to one dimension and built the following example :   MSE = 1/n[SUM(Y_hat_i - Y_i)**2]   Given the following distribution Y = [5,3,2,7,4], minimizing MSE I intended as in the following: I should find a function Y_hat such that when it is applied to the MSE formula (more specifically to each element of the Y distribution), we are sure that we obtain the minimum value. For simplicity, I could consider the Y_hat as any measure or function for the central tendency, including, mean, median, mode, etc.  Lets suppose, Y_hat = mean (=4.2 for our distribution), therefore, I did all the calculations such as:  1/5 [(4.2-5)**2 + (4.2-3)**2+ (4.2-2)**2 + (4.2-7)**2  + (4.2-4)**2 ] = 2.96   Let's suppose, Y_hat = median (=4 for our distribution), therefore, I did all the calculations such as:  1/5 [(4-5)**2 + (4-3)**2+ (4-2)**2 + (4-7)**2  + (4-4)**2 ] = 2.8   If I did all the calculation correctly, the result shows that for this case, the median is minimizing better than the mean.  I am sure, I am doing something wrong and missing important aspects of the overall reasoning.  Please, could you provide any clarification on the above topic? I would really appreciate it.  Many Thanks in advance, Best Regards, Carlo Explosive AR(MA) processes are stationary? Is it possible to choose which OS will be loaded using a hardware switch? What makes Stealing Signs wrong? I am looking for a multivariable calculus book that is really physics oriented.  Anyone know of any?  EDIT: My wife is looking to brush up on multivariable at the same time she needs to brush up on the related physics. How to transfer a DVD to my hard drive How fast would the Earth need to spin for us to feel weightless? It's a classic question with many answers all over the Internet, but none here so I figured I'd ask it:  How fast would the Earth need to spin for a person (or anything for that matter) to feel weightless while on the surface at the equator?    In this situation everything on the Earth's surface would essentially be in orbit around the Earth at the radius of the Earth's surface (let us assume the atmosphere was also spun up to this angular velocity so there would be no air drag slowing things down).  Let us also say by "surface of the Earth" we mean mean sea level.  You can decide for yourself if/how to factor in the bulge of the Earth.  You can assume that the Earth somehow is able to maintain its present shape while spinning up.  Any comments on whether an Earth spinning slightly faster than this speed will cause it to break apart or not will also be appreciated. How is listed DPS calculated when dual-wielding weapons? I was trying out the dual-wielding in Diablo 3, when I noticed really strange. When I equipped my off-hand, which has 0.5 less damage than my main-hand. My overall damage actually went down. So my question is, how does the dual-wielding mechanic work for calculating damage? It seems rather odd that my overall damage should be more with one weapon than with two. I have two exchange accounts on my iPhone 4. One that connects to my gmail, the other connects to my work's Lotus Notes. There are no overlapping contacts in the two accounts. There are also no contacts saved locally on my phone.   When I enable contacts in both accounts, I get two identical entries for each of the contacts in my gmail. If I disable the Notes exchange account, then there are no more duplicates. If I have Notes contacts enabled, and gmail contacts disabled then I have no contacts at all.  Does anyone know what is going on? Is this a problem with having multiple exchange accounts or is it a Lotus Traveler problem? (I tend to blame Notes for all the trouble in the world, but that is just my bias)  Thanks all. How can I make it so that each space has its own isolated dock?  Basically what I'm looking for is:   The dock in one space should not show the icon of an app that was open in another space. If I have the same program open in two different spaces, clicking on the icon in one space should not go to the app in the other space.   Is this possible natively, or with a third party program? How can I add a program to the context menu of all files? so I am trying to show that $f(x)$ divides $g(x)$ for all polynomials $g(x)$ satisfying that $g(A)=0$ where $f(x)$ is the minimal polynomial of a square matrix $A$.  I know from my professor that $f(x)$ is the minimal polynomial of $A$ so $f(A)=0$ so then $g(A)=0$. Therefore, $f(x)$ divides $g(x)$, i.e. $g(x)=f(x)h(x)$ where $h(x)$ is some other polynomial.  My prof told us to solve this question we need to let $b(x)=gcd((f(x),g(x))$ and by using Bezout's Identity, we need to show that $b(A)=0$. I am just having a little trouble trying to prove this. I know that this identity says:     For two polynomials $f_1(x)$ and $f_2(x)$, there exist polynomials   $g_1(x)$ and $g_2(x)$ such that $g_1(x)f_1(x) + g_2(x)f_2(x) = &gt; gcd(f_1(x), f_2(x))$.   And the uniqueness of minimal polynomial theorem is:     For a square matrix $A$, if $f_1(A) = f_2(A) = 0$ for two polynomials   $f_1(x)$ and $f_2(x)$, then $g(A) = 0$ for $g(x) = gcd(f_1(x), &gt; f_2(x))$. So the minimal polynomial of $A$ is unique up to a scalar.   So since $f(x)$ is already the minimal polynomial, I know that the $deg(b(x))=deg(f(x))$. I know how to prove the Bezout identity using the Euclidean algorithm, I'm just not exactly sure how I would show all of this using the notation he gave us of $b(x)=gcd((f(x),g(x))$. Any help at all would be appreciated. Okay setting the scene. I have three tables, (Table1, Table2 and DataTable) and I want to insert into Table1 and Table2 using DataTable as source. So for every row in DataTable I want a row in Table1 and Table2, and Table2 needs to have the inserted id (PK) from Table1...  If I were to do this...  INSERT INTO Table1 SELECT A, B, C FROM MyTable INSERT INTO Table2 SELECT IDENTITY_INSERT(), D, E, F FROM MyTable   I'd get the ID of the last inserted record into Table1.  Is a CURSOR or WHILE loop the only ways to do this? Subdomain versus subdirectory I recently moved from having a main site like www.example.com with a subdomain associated site yyy.example.com, to moving everything off the subdomain to a subdirectory like www.example.com/yyy/, with the same hierarchy underneath the subdirectory, and now yyy.example.com is just a redirect page to the subdirectory, so yyy.example.com/abc/page-x is redirected to www.example.com/yyy/abc/page-x and so on.  The effect has been that the traffic increased by several times (the total page views are more than ten times at the present rate) what it was to the yyy subdomain. Previously almost all of the traffic to the yyy subdomain was from the www site. This is from monitoring the old yyy site for a year or more.  I'm curious to know if there's any research or results which would indicate whether this is universal (subdirectories beat subdomains) or "just me". How to combine two strings together in PHP? Intermediate ring between a field and an algebraic extension. We noticed that lots of bugs in our software developed in C# (or Java) cause a NullReferenceException.  Is there a reason why "null" has even been included in the language?  After all, if there were no "null", I would have no bug, right?  In other words, what feature in the language couldn't work without null? Does $E = mc^2$ apply to photons? Photons are massless, but if $m = 0$ and , then $E = 0c^2 = 0$. This would say that photons have no energy, which is not true.  However, given the formula $E = ℎf$, a photon does have energy as $ℎ$ is a non-zero constant and photons with a zero frequency do not exist.  What am I missing here, or does the famous formula not apply to photons? I need help!  I need to prove that for any $2 \le n,k$ positive integers $(n - 1)^2 \mid n^k -1$ if and only if $(n - 1) \mid k$  Thanks!