Reputation: 1
How to resolve OutOfMemoryError in weblogic server
Increase Heap size - -Xmx10G, -Xms10G implemented SFTP instead of FTP
byte[] fileArr = null; ByteArrayOutputStream out;
StringBuilder strBuild = new StringBuilder();
strBuild.append(path);
strBuild.append(fileName);
InputStream inputStr = null;
BufferedInputStream bis = null;
ByteBuffer buffer = null;
ReadableByteChannel inputChannel = null;
WritableByteChannel outputChannel = null;
try {
inputStr = this.sftpClient.getInputStream(strBuild.toString());
if(READ_BUFFER_SIZE <= 0){
buffer = ByteBuffer.allocateDirect(DEFAULT_BUFFER_SIZE);
}
else{
buffer = ByteBuffer.allocateDirect(READ_BUFFER_SIZE);
}
bis = new BufferedInputStream(inputStr);
out = new ByteArrayOutputStream();
inputChannel = Channels.newChannel(bis);
outputChannel = Channels.newChannel(out);
while (inputChannel.read(buffer) > 0) {
buffer.flip();
outputChannel.write(buffer);
buffer.compact();
}
Need response in ByteArray of input file
Upvotes: 0
Views: 81
Reputation: 344
In your coude I don't see where you close your Streams. Probably server keeps your open buffers.
Insert a try-with-resource (https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html) or close your streams in your code
Upvotes: 1