Skip to content

Commit

Permalink
Fix uploading on Java 17. Frankly I have no idea why this originally …
Browse files Browse the repository at this point in the history
…worked. Closes #186.
  • Loading branch information
MER-C committed Jan 23, 2022
1 parent ba5635d commit 02a2e8d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/org/wikipedia/Wiki.java
Original file line number Diff line number Diff line change
Expand Up @@ -8128,7 +8128,7 @@ public String makeApiCall(Map<String, String> getparams, Map<String, Object> pos
boolean isPOST = (postparams != null && !postparams.isEmpty());
StringBuilder stringPostBody = new StringBuilder();
boolean multipart = false;
ArrayList<byte[]> multipartPostBody = new ArrayList<>();
ByteArrayOutputStream multipartPostBody = new ByteArrayOutputStream();
String boundary = "----------NEXT PART----------";
if (isPOST)
{
Expand All @@ -8150,18 +8150,18 @@ public String makeApiCall(Map<String, String> getparams, Map<String, Object> pos
for (Map.Entry<String, ?> entry : postparams.entrySet())
{
Object value = entry.getValue();
multipartPostBody.add((nextpart + entry.getKey() + "\"").getBytes(StandardCharsets.UTF_8));
multipartPostBody.write((nextpart + entry.getKey() + "\"").getBytes(StandardCharsets.UTF_8));
if (value instanceof String)
multipartPostBody.add(("Content-Type: text/plain; charset=UTF-8\r\n\r\n" + (String)value + "\r\n")
multipartPostBody.write(("Content-Type: text/plain; charset=UTF-8\r\n\r\n" + (String)value + "\r\n")
.getBytes(StandardCharsets.UTF_8));
else if (value instanceof byte[])
{
multipartPostBody.add("Content-Type: application/octet-stream\r\n\r\n".getBytes(StandardCharsets.UTF_8));
multipartPostBody.add((byte[])value);
multipartPostBody.add("\r\n".getBytes(StandardCharsets.UTF_8));
multipartPostBody.write("Content-Type: application/octet-stream\r\n\r\n".getBytes(StandardCharsets.UTF_8));
multipartPostBody.write((byte[])value);
multipartPostBody.write("\r\n".getBytes(StandardCharsets.UTF_8));
}
}
multipartPostBody.add((boundary + "--\r\n").getBytes(StandardCharsets.UTF_8));
multipartPostBody.write((boundary + "--\r\n").getBytes(StandardCharsets.UTF_8));
}
else
{
Expand Down Expand Up @@ -8189,7 +8189,7 @@ else if (value instanceof byte[])
if (isPOST)
{
if (multipart)
connection = connection.POST(HttpRequest.BodyPublishers.ofByteArrays(multipartPostBody))
connection = connection.POST(HttpRequest.BodyPublishers.ofByteArray(multipartPostBody.toByteArray()))
.header("Content-Type", "multipart/form-data; boundary=" + boundary);
else
connection = connection.POST(HttpRequest.BodyPublishers.ofString(stringPostBody.toString()))
Expand Down

0 comments on commit 02a2e8d

Please sign in to comment.