diff --git a/LaunchServer/source/response/update/UpdateResponse.java b/LaunchServer/source/response/update/UpdateResponse.java index 6555b95..d549548 100644 --- a/LaunchServer/source/response/update/UpdateResponse.java +++ b/LaunchServer/source/response/update/UpdateResponse.java @@ -2,6 +2,7 @@ import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; import java.util.Deque; @@ -47,7 +48,8 @@ dirStack.add(hdir.object); // Perform update - HOutput fileOutput = server.config.compress ? new HOutput(new DeflaterOutputStream(output.stream, IOHelper.newDeflater(), IOHelper.BUFFER_SIZE, true)) : output; + // noinspection IOResourceOpenedButNotSafelyClosed + OutputStream fileOutput = server.config.compress ? new DeflaterOutputStream(output.stream, IOHelper.newDeflater(), IOHelper.BUFFER_SIZE, true) : output.stream; Action[] actionsSlice = new Action[UpdateRequest.MAX_QUEUE_SIZE]; loop: while (true) { @@ -86,13 +88,13 @@ // Resolve and write file Path file = dir.resolve(action.name); if (Files.size(file) != hFile.size()) { - fileOutput.writeUnsignedByte(0x0); + fileOutput.write(0x0); fileOutput.flush(); throw new IOException("Unknown hashed file: " + action.name); } - fileOutput.writeUnsignedByte(0xFF); + fileOutput.write(0xFF); try (InputStream fileInput = IOHelper.newInput(file)) { - IOHelper.transfer(fileInput, fileOutput.stream); + IOHelper.transfer(fileInput, fileOutput); } break; case CD_BACK: diff --git a/Launcher/source/request/update/UpdateRequest.java b/Launcher/source/request/update/UpdateRequest.java index 87ba000..e76eb28 100644 --- a/Launcher/source/request/update/UpdateRequest.java +++ b/Launcher/source/request/update/UpdateRequest.java @@ -2,6 +2,7 @@ import java.io.EOFException; import java.io.IOException; +import java.io.InputStream; import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; @@ -116,7 +117,8 @@ output.flush(); // Perform actions - HInput fileInput = compress ? new HInput(new InflaterInputStream(input.stream, IOHelper.newInflater(), IOHelper.BUFFER_SIZE)) : input; + // noinspection IOResourceOpenedButNotSafelyClosed + InputStream fileInput = compress ? new InflaterInputStream(input.stream, IOHelper.newInflater(), IOHelper.BUFFER_SIZE) : input.stream; for (int i = 0; i < length; i++) { Action action = actionsSlice[i]; switch (action.type) { @@ -126,7 +128,7 @@ break; case GET: Path targetFile = currentDir.resolve(action.name); - if (fileInput.readUnsignedByte() != 0xFF) { + if (fileInput.read() != 0xFF) { throw new IOException("Serverside cached size mismath for file " + action.name); } downloadFile(targetFile, (HashedFile) action.entry, fileInput); @@ -180,7 +182,7 @@ } } - private void downloadFile(Path file, HashedFile hFile, HInput input) throws IOException { + private void downloadFile(Path file, HashedFile hFile, InputStream input) throws IOException { String filePath = IOHelper.toString(dir.relativize(file)); updateState(filePath, 0L, hFile.size); @@ -193,7 +195,7 @@ byte[] bytes = IOHelper.newBuffer(); while (downloaded < hFile.size) { int remaining = (int) Math.min(hFile.size - downloaded, bytes.length); - int length = input.stream.read(bytes, 0, remaining); + int length = input.read(bytes, 0, remaining); if (length < 0) { throw new EOFException(String.format("%d bytes remaining", hFile.size - downloaded)); }