Skip to content

Commit

Permalink
Use FileWriter instead of Files.copy
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre601 committed Aug 6, 2022
1 parent ab32f30 commit f7c92c6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,9 @@
import okhttp3.Response;
import okhttp3.ResponseBody;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.List;
import java.util.concurrent.CompletableFuture;

Expand Down Expand Up @@ -84,7 +80,7 @@ public CompletableFuture<VersionsFile> updateFile(String url){
// User is using old versions.json URL
if(newVersions.getFileVersion() == -1){
logger.warn("Remote JSON file does not have a 'file_version' property set!");
logger.warn("Make sure the URL points to an updated version.");
logger.warn("Make sure the URL points to an updated versions file.");
logger.warnFormat("New URL: %s", OneVersionRemake.DEF_VERSIONS_URL);

return null;
Expand Down Expand Up @@ -119,10 +115,13 @@ private VersionsFile copyAndUpdate(String json){
if(json == null)
return null;

InputStream stream = new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8));

try{
Files.copy(stream, file, StandardCopyOption.REPLACE_EXISTING);
FileWriter fileWriter = new FileWriter(file.toFile(), false);
BufferedWriter writer = new BufferedWriter(fileWriter);

writer.write(json);
writer.close();

return (versions = getVersionsFile(json));
}catch(IOException ex){
logger.warn("Encountered IOException while saving the versions.json file.", ex);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<plugin.version>3.11.1</plugin.version>
<plugin.version>3.11.2</plugin.version>
<plugin.description>Only allow specific client versions on your Network.</plugin.description>

<maven.compiler.target>11</maven.compiler.target>
Expand Down
7 changes: 7 additions & 0 deletions versions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{
"note": [
"This file is no longer updated and used by the latest OneVersionRemake version.",
"The latest version can be found at https://github.com/Andre601/andre601.github.io under",
"/site/oneversionremake/protocol_versions.json",
"",
"This file will no longer receive updates."
],
"759": {
"name": "1.19",
"major": "1.19.x"
Expand Down

0 comments on commit f7c92c6

Please sign in to comment.