Skip to content

Commit

Permalink
Replace InputStream.readAllBytes() which is only available in java 9 …
Browse files Browse the repository at this point in the history
…or higher.
  • Loading branch information
IntegratedQuantum committed Nov 2, 2020
1 parent 94857aa commit 1503d4a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/io/cubyz/github/GitHubConnection.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package io.cubyz.github;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
Expand Down Expand Up @@ -33,7 +34,7 @@ public static GithubRelease[] downloadReleaseData() {
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.connect();
InputStream stream = connection.getInputStream();
json = new String(stream.readAllBytes());
json = new String(readAllBytes(stream));
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
Expand Down Expand Up @@ -63,4 +64,16 @@ public static GithubRelease[] downloadReleaseData() {
});
return list.toArray(new GithubRelease[0]);
}
public static byte[] readAllBytes(InputStream inputStream) throws IOException {
final int bufLen = 1024;
byte[] buf = new byte[bufLen];
int readLen;

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

while ((readLen = inputStream.read(buf, 0, bufLen)) != -1)
outputStream.write(buf, 0, readLen);

return outputStream.toByteArray();
}
}

0 comments on commit 1503d4a

Please sign in to comment.