I am getting an OutOfMemoryError from the following method. Please find the method and error below. This method is invoked 1000's of times within the project. So I am confused whether this error is because of the input
string size or OR due to recursive invocation.
public static InputStream stringToStream(String inputString) {
InputStream inputStream = null;
try {
InputStream inputStream = new ByteArrayInputStream(inputString.getBytes("UTF-8"));
} catch (UnsupportedEncodingException exp) {
exp.printStackTrace();
}
return inputStream;
}
Exception in
thread "Thread-61" java.lang.OutOfMemoryError:
Java heap space
at java.util.Arrays.copyOf(Unknown Source)
at java.lang.StringCoding.safeTrim(Unknown Source)
at java.lang.StringCoding.access$300(Unknown Source)
at java.lang.StringCoding$StringEncoder.encode(Unknown Source)
at java.lang.StringCoding.encode(Unknown Source)
at java.lang.String.getBytes(Unknown Source)
Thanks for reading this and will appreciate any inputs or advice.