Hi,
I have problem with this readInputStream method. I have checked in
(postgresql)database, which i
used column data type is bytea its default column size 1gb data. I will
explain my problem clearly,
Step1 :
I checked in java file itself,
public static void main(String args[])
{
byte[] filedata = readInputStream(new FileInputStream("test.pdf"));
// byte filedata = null
// DB code to store binary data
}
If, i run the code, it shows outofmemory error java heap size.
/** Read an input stream in its entirety into a byte array */
public static byte[] readInputStream(InputStream inputStream) throws
IOException {
int bufSize = 1024 * 1024;
byte[] content;
List<byte[]> parts = new LinkedList();
InputStream in = new BufferedInputStream(inputStream);
byte[] readBuffer = new byte[bufSize];
byte[] part = null;
int bytesRead = 0;
// read everyting into a list of byte arrays
while ((bytesRead = in.read(readBuffer, 0, bufSize)) != -1) {
part = new byte[bytesRead];
System.arraycopy(readBuffer, 0, part, 0, bytesRead);
parts.add(part);
}
// calculate the total size
int totalSize = 0;
for (byte[] partBuffer : parts) {
totalSize += partBuffer.length;
}
// allocate the array
content = new byte[totalSize];
int offset = 0;
for (byte[] partBuffer : parts) {
System.arraycopy(partBuffer, 0, content, offset,
partBuffer.length);
offset += partBuffer.length;
}
return content;
}
--
View this message in context:
http://www.nabble.com/Huge-File-upload-in-struts-2-tp23870472p23881060.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]