Skip to content

Commit

Permalink
Merge pull request yarl#162 from Abbe98/gson-bump
Browse files Browse the repository at this point in the history
update gson
  • Loading branch information
Abbe98 authored Mar 1, 2022
2 parents f96e92c + eaebf27 commit 1da70e4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
Binary file removed lib/gson-2.8.5.jar
Binary file not shown.
Binary file added lib/gson-2.9.0.jar
Binary file not shown.
36 changes: 17 additions & 19 deletions src/pattypan/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,17 @@
*/
package pattypan;

import edu.stanford.ejalbert.BrowserLauncher;
import edu.stanford.ejalbert.exception.BrowserLaunchingInitializingException;
import edu.stanford.ejalbert.exception.UnsupportedOperatingSystemException;
import java.awt.Desktop;
import java.awt.EventQueue;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse.BodyHandlers;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -50,6 +48,10 @@
import java.util.Set;
import java.util.logging.Level;
import java.util.stream.Collectors;

import edu.stanford.ejalbert.BrowserLauncher;
import edu.stanford.ejalbert.exception.BrowserLaunchingInitializingException;
import edu.stanford.ejalbert.exception.UnsupportedOperatingSystemException;
import javafx.geometry.HPos;
import javafx.scene.layout.ColumnConstraints;

Expand Down Expand Up @@ -255,22 +257,18 @@ public static String getFileChecksum(MessageDigest digest, File file) throws IOE
}

public static String readUrl(String urlString) throws Exception {
BufferedReader reader = null;
try {
URL url = new URL(urlString);
reader = new BufferedReader(new InputStreamReader(url.openStream()));
StringBuilder buffer = new StringBuilder();
int read;
char[] chars = new char[1024];
while ((read = reader.read(chars)) != -1) {
buffer.append(chars, 0, read);
}
HttpClient client = HttpClient.newHttpClient();

return buffer.toString();
} finally {
if (reader != null) {
reader.close();
}
HttpRequest request = HttpRequest.newBuilder(
URI.create(urlString))
.header("user-agent", Settings.USERAGENT)
.build();

var response = client.send(request, BodyHandlers.ofString());
return response.body();
} catch (Exception e) {
throw new Exception("Error while getting JSON from " + urlString);
}
}

Expand Down
12 changes: 7 additions & 5 deletions src/pattypan/panes/StartPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@
*/
package pattypan.panes;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.net.UnknownHostException;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.logging.Level;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import javafx.geometry.Pos;
import javafx.scene.control.Hyperlink;
import javafx.scene.layout.GridPane;
Expand Down Expand Up @@ -158,7 +160,7 @@ public ArrayList<String> getVersions() throws Exception {
ArrayList<String> versions = new ArrayList<>();
String json = Util.readUrl("https://api.github.com/repos/yarl/pattypan/releases");

JsonArray releases = new JsonParser().parse(json).getAsJsonArray();
JsonArray releases = JsonParser.parseString(json).getAsJsonArray();
for (JsonElement element : releases) {
JsonObject release = element.getAsJsonObject();
boolean draft = release.get("draft").getAsBoolean();
Expand Down

0 comments on commit 1da70e4

Please sign in to comment.