Skip to content

Commit 24f811a

Browse files
committed
#303 fix for input stream reading bug (due to is.available() being unreliable)
1 parent 0efebcf commit 24f811a

File tree

1 file changed

+7
-5
lines changed
  • modules/core-module/src/main/java/org/simplejavamail/internal/util

1 file changed

+7
-5
lines changed

modules/core-module/src/main/java/org/simplejavamail/internal/util/MiscUtil.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,14 @@ public static String readInputStreamToString(@NotNull final InputStream inputStr
127127
@NotNull
128128
public static byte[] readInputStreamToBytes(@NotNull final InputStream inputStream)
129129
throws IOException {
130-
try (InputStream is = inputStream) {
131-
byte[] targetArray = new byte[is.available()];
132-
//noinspection ResultOfMethodCallIgnored
133-
is.read(targetArray);
134-
return targetArray;
130+
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
131+
byte[] data = new byte[1024];
132+
int read;
133+
while ((read = inputStream.read(data, 0, data.length)) != -1) {
134+
buffer.write(data, 0, read);;
135135
}
136+
buffer.flush();
137+
return buffer.toByteArray();
136138
}
137139

138140
/**

0 commit comments

Comments
 (0)