diff --git a/.gitignore b/.gitignore
index 5c1cf006..8eb22fd9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,11 @@ target/
*.project
*.classpath
*.prefs
+
+# IDE setting files
+.vscode/
+
+.settings/
+.factorypath
+
+dependency-reduced-pom.xml
\ No newline at end of file
diff --git a/build.xml b/build.xml
deleted file mode 100644
index 66dc9d49..00000000
--- a/build.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/libs/Essentials.jar b/libs/Essentials.jar
deleted file mode 100644
index 3b5813f3..00000000
Binary files a/libs/Essentials.jar and /dev/null differ
diff --git a/libs/EssentialsGroupManager.jar b/libs/EssentialsGroupManager.jar
deleted file mode 100644
index 181ebccb..00000000
Binary files a/libs/EssentialsGroupManager.jar and /dev/null differ
diff --git a/libs/Factions.jar b/libs/Factions.jar
deleted file mode 100644
index 6c5b798f..00000000
Binary files a/libs/Factions.jar and /dev/null differ
diff --git a/libs/GriefPrevention.jar b/libs/GriefPrevention.jar
deleted file mode 100644
index 5e0afb84..00000000
Binary files a/libs/GriefPrevention.jar and /dev/null differ
diff --git a/libs/LWC.jar b/libs/LWC.jar
deleted file mode 100644
index ba3b7f5c..00000000
Binary files a/libs/LWC.jar and /dev/null differ
diff --git a/libs/MassiveCore.jar b/libs/MassiveCore.jar
deleted file mode 100644
index e23d12b6..00000000
Binary files a/libs/MassiveCore.jar and /dev/null differ
diff --git a/libs/MyWarp.jar b/libs/MyWarp.jar
deleted file mode 100644
index 3126381b..00000000
Binary files a/libs/MyWarp.jar and /dev/null differ
diff --git a/libs/PreciousStones.jar b/libs/PreciousStones.jar
deleted file mode 100644
index b3cdd7e1..00000000
Binary files a/libs/PreciousStones.jar and /dev/null differ
diff --git a/libs/Residence.jar b/libs/Residence.jar
deleted file mode 100644
index a79c2675..00000000
Binary files a/libs/Residence.jar and /dev/null differ
diff --git a/libs/Towny.jar b/libs/Towny.jar
deleted file mode 100644
index c7b248f7..00000000
Binary files a/libs/Towny.jar and /dev/null differ
diff --git a/libs/Vault.jar b/libs/Vault.jar
deleted file mode 100644
index d4d4ecc7..00000000
Binary files a/libs/Vault.jar and /dev/null differ
diff --git a/libs/WorldEdit.jar b/libs/WorldEdit.jar
deleted file mode 100644
index 1bc1cd6b..00000000
Binary files a/libs/WorldEdit.jar and /dev/null differ
diff --git a/libs/WorldGuard.jar b/libs/WorldGuard.jar
deleted file mode 100644
index 1114fe6e..00000000
Binary files a/libs/WorldGuard.jar and /dev/null differ
diff --git a/libs/downloads.txt b/libs/downloads.txt
new file mode 100644
index 00000000..caed9448
--- /dev/null
+++ b/libs/downloads.txt
@@ -0,0 +1,16 @@
+Download jars from these links and put in libs directory.
+
+paperspigot
+https://papermc.io/downloads
+download paperclip and run server.
+then, copy ./cache/patched_.jar into libs.
+finally, rename patched_.jar to paperspigot.jar
+
+Factions & MassiveCore
+https://www.spigotmc.org/resources/factions3-for-1-13.63602/
+
+Residence
+https://zrips.net/Residence/
+
+MyWarp
+https://dev.bukkit.org/projects/mywarp
\ No newline at end of file
diff --git a/libs/paperspigot.jar b/libs/paperspigot.jar
deleted file mode 100644
index fdc3ac98..00000000
Binary files a/libs/paperspigot.jar and /dev/null differ
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 00000000..61da86c3
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,234 @@
+
+ 4.0.0
+ autosaveworld
+ AutoSaveWorld
+ 4.15
+ Multifunctional plugin to manage server easier
+
+
+
+ jitpack.io
+ https://jitpack.io
+
+
+ enginehub-maven
+ https://maven.enginehub.org/repo/
+
+
+ essentialsx-repo
+ https://ci.ender.zone/plugin/repository/everything/
+
+
+
+ elMakers-repo
+ http://maven.elmakers.com/repository/
+
+
+
+
+
+
+ com.dropbox.core
+ dropbox-core-sdk
+ 3.1.5
+
+
+ com.google.api-client
+ google-api-client
+ 1.30.11
+
+
+ com.google.apis
+ google-api-services-drive
+ v3-rev197-1.25.0
+
+
+ com.google.auth
+ google-auth-library-oauth2-http
+ 0.22.0
+
+
+ com.jcraft
+ jsch
+ 0.1.55
+
+
+ commons-net
+ commons-net
+ 3.7.2
+
+
+
+
+ com.sk89q.worldedit
+ worldedit-bukkit
+ 7.2.0
+ provided
+
+
+ com.sk89q.worldguard
+ worldguard-bukkit
+ 7.0.4
+ provided
+
+
+ com.github.MilkBowl
+ VaultAPI
+ 1.7
+ provided
+
+
+ net.ess3
+ EssentialsX
+ 2.18.1
+ provided
+
+
+ com.griefcraft.lwc
+ LWCX
+ 2.2.6
+ provided
+
+
+ com.github.TechFortress
+ GriefPrevention
+ 16.7.1
+ provided
+
+
+ com.github.GroupManager
+ GroupManager
+ v0.2.0
+ provided
+
+
+ net.sacredlabyrinth.Phaed
+ PreciousStones
+ 1.16.1.12
+ provided
+
+
+ com.github.TownyAdvanced
+ Towny
+ 0.96.3.0
+ provided
+
+
+
+
+ com.destroystokyo.paper
+ paper
+ 1.16.4-R0.1-SNAPSHOT
+ system
+ ${basedir}/libs/paperspigot.jar
+
+
+ com.massivecraft.massivecore
+ MassiveCore
+ 3.2.3
+ system
+ ${basedir}/libs/MassiveCore.jar
+
+
+ com.massivecraft.factions
+ Factions
+ 3.2.3
+ system
+ ${basedir}/libs/Factions.jar
+
+
+ com.bekvon.bukkit.residence
+ Residence
+ 4.9.2.0
+ system
+ ${basedir}/libs/Residence.jar
+
+
+ io.github.mywarp.mywarp
+ MyWarp
+ 3.1
+ system
+ ${basedir}/libs/MyWarp.jar
+
+
+
+
+
+
+ .
+ true
+ src/main/resources/
+
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 3.2.0
+
+ ${project.name}
+
+
+ true
+ true
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+ ${java.version}
+ ${java.version}
+ UTF-8
+ false
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ 3.2.3
+
+
+ package
+
+ shade
+
+
+ true
+
+
+ com.dropbox
+ autosaveworld.zlibs.com.dropbox
+
+
+ com.fasterxml
+ autosaveworld.zlibs.com.fasterxml
+
+
+ com.google
+ autosaveworld.zlibs.com.google
+
+
+ com.jcraft
+ autosaveworld.zlibs.com.jcraft
+
+
+ org.apache.commons.net
+ autosaveworld.zlibs.org.apache.commons.net
+
+
+
+
+
+
+
+
+
+ UTF-8
+ UTF-8
+ 10
+
+
\ No newline at end of file
diff --git a/src/autosaveworld/zlibs/com/dropbox/core/ApiErrorResponse.java b/src/autosaveworld/zlibs/com/dropbox/core/ApiErrorResponse.java
deleted file mode 100644
index b39fd8f4..00000000
--- a/src/autosaveworld/zlibs/com/dropbox/core/ApiErrorResponse.java
+++ /dev/null
@@ -1,75 +0,0 @@
-package autosaveworld.zlibs.com.dropbox.core;
-
-import java.io.IOException;
-
-import autosaveworld.zlibs.com.dropbox.core.stone.StoneSerializer;
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonGenerationException;
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonGenerator;
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonParseException;
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonParser;
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonToken;
-
-final class ApiErrorResponse {
- private final T error;
- private LocalizedText userMessage;
-
- public ApiErrorResponse(T error, LocalizedText userMessage) {
- if (error == null) {
- throw new NullPointerException("error");
- }
- this.error = error;
- this.userMessage = userMessage;
- }
-
- public T getError() {
- return error;
- }
-
- public LocalizedText getUserMessage() {
- return userMessage;
- }
-
- /**
- * For internal use only.
- */
- static final class Serializer extends StoneSerializer> {
- private StoneSerializer errSerializer;
-
- public Serializer(StoneSerializer errSerializer) {
- this.errSerializer = errSerializer;
- }
-
- @Override
- public void serialize(ApiErrorResponse value, JsonGenerator g) throws IOException, JsonGenerationException {
- throw new UnsupportedOperationException("Error wrapper serialization not supported.");
- }
-
- @Override
- public ApiErrorResponse deserialize(JsonParser p) throws IOException, JsonParseException {
- T error = null;
- LocalizedText userMessage = null;
-
- expectStartObject(p);
- while (p.getCurrentToken() == JsonToken.FIELD_NAME) {
- String field = p.getCurrentName();
- p.nextToken();
- if ("error".equals(field)) {
- error = errSerializer.deserialize(p);
- } else if ("user_message".equals(field)) {
- userMessage = LocalizedText.STONE_SERIALIZER.deserialize(p);
- } else {
- skipValue(p);
- }
- }
- if (error == null) {
- throw new JsonParseException(p, "Required field \"error\" missing.");
- }
-
- ApiErrorResponse value = new ApiErrorResponse(error, userMessage);
- expectEndObject(p);
-
- return value;
- }
- }
-}
-
diff --git a/src/autosaveworld/zlibs/com/dropbox/core/BadRequestException.java b/src/autosaveworld/zlibs/com/dropbox/core/BadRequestException.java
deleted file mode 100644
index dbdb9cc1..00000000
--- a/src/autosaveworld/zlibs/com/dropbox/core/BadRequestException.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package autosaveworld.zlibs.com.dropbox.core;
-
-/**
- * This is what is thrown when the Dropbox server tells us that it didn't like something about our
- * request. This corresponds to the HTTP 400 status code.
- */
-public class BadRequestException extends ProtocolException {
- private static final long serialVersionUID = 0;
-
- public BadRequestException(String requestId, String message) {
- super(requestId, message);
- }
-}
diff --git a/src/autosaveworld/zlibs/com/dropbox/core/BadResponseCodeException.java b/src/autosaveworld/zlibs/com/dropbox/core/BadResponseCodeException.java
deleted file mode 100644
index 9cc7e0a5..00000000
--- a/src/autosaveworld/zlibs/com/dropbox/core/BadResponseCodeException.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package autosaveworld.zlibs.com.dropbox.core;
-
-/**
- * Thrown when the Dropbox server responds with an HTTP status code we didn't expect.
- */
-public class BadResponseCodeException extends BadResponseException {
- private static final long serialVersionUID = 0L;
-
- private final int statusCode;
-
- public BadResponseCodeException(String requestId, String message, int statusCode) {
- super(requestId, message);
- this.statusCode = statusCode;
- }
-
- public BadResponseCodeException(String requestId, String message, int statusCode, Throwable cause) {
- super(requestId, message, cause);
- this.statusCode = statusCode;
- }
-
- /**
- * Returns HTTP status code received from the Dropbox server.
- *
- * @return HTTP status code returned by Dropbox server
- */
- public int getStatusCode() {
- return statusCode;
- }
-}
-
diff --git a/src/autosaveworld/zlibs/com/dropbox/core/BadResponseException.java b/src/autosaveworld/zlibs/com/dropbox/core/BadResponseException.java
deleted file mode 100644
index 855f8274..00000000
--- a/src/autosaveworld/zlibs/com/dropbox/core/BadResponseException.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package autosaveworld.zlibs.com.dropbox.core;
-
-/**
- * Thrown when we the response from the Dropbox server isn't something we expect.
- * For example, if the JSON returned by the server is malformed or missing fields.
- */
-public class BadResponseException extends ProtocolException {
- private static final long serialVersionUID = 0;
-
- public BadResponseException(String requestId, String message) {
- super(requestId, message);
- }
-
- public BadResponseException(String requestId, String message, Throwable cause) {
- super(requestId, message, cause);
- }
-}
-
diff --git a/src/autosaveworld/zlibs/com/dropbox/core/DbxApiException.java b/src/autosaveworld/zlibs/com/dropbox/core/DbxApiException.java
deleted file mode 100644
index c0504114..00000000
--- a/src/autosaveworld/zlibs/com/dropbox/core/DbxApiException.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package autosaveworld.zlibs.com.dropbox.core;
-
-/**
- * Base class for API-specific exceptions raised by API v2 routes.
- */
-public class DbxApiException extends DbxException {
- private static final long serialVersionUID = 0L;
-
- private final LocalizedText userMessage;
-
- public DbxApiException(String requestId, LocalizedText userMessage, String message) {
- super(requestId, message);
- this.userMessage = userMessage;
- }
-
- public DbxApiException(String requestId, LocalizedText userMessage, String message, Throwable cause) {
- super(requestId, message, cause);
- this.userMessage = userMessage;
- }
-
- /**
- * Returns a human-readable message that can be displayed to the end user.
- *
- *
If no such message is available, then this method returns {@code null}.
- *
- * @return human-readable message to display to end user, or {@code null} if unavailable
- */
- public LocalizedText getUserMessage() {
- return userMessage;
- }
-
- protected static String buildMessage(String routeName, LocalizedText userMessage) {
- return buildMessage(routeName, userMessage, null);
- }
-
- protected static String buildMessage(String routeName, LocalizedText userMessage, Object errorValue) {
- StringBuilder sb = new StringBuilder();
- sb.append("Exception in ").append(routeName);
- if (errorValue != null) {
- sb.append(": ").append(errorValue);
- }
- if (userMessage != null) {
- sb.append(" (user message: ").append(userMessage).append(")");
- }
- return sb.toString();
- }
-}
diff --git a/src/autosaveworld/zlibs/com/dropbox/core/DbxAppInfo.java b/src/autosaveworld/zlibs/com/dropbox/core/DbxAppInfo.java
deleted file mode 100644
index 2fe8f53d..00000000
--- a/src/autosaveworld/zlibs/com/dropbox/core/DbxAppInfo.java
+++ /dev/null
@@ -1,242 +0,0 @@
-package autosaveworld.zlibs.com.dropbox.core;
-
-import static autosaveworld.zlibs.com.dropbox.core.util.StringUtil.jq;
-
-import java.io.IOException;
-
-import autosaveworld.zlibs.com.dropbox.core.json.JsonReadException;
-import autosaveworld.zlibs.com.dropbox.core.json.JsonReader;
-import autosaveworld.zlibs.com.dropbox.core.util.DumpWriter;
-import autosaveworld.zlibs.com.dropbox.core.util.Dumpable;
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonLocation;
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonParseException;
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonParser;
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonToken;
-
-/*>>> import checkers.nullness.quals.Nullable; */
-
-/**
- * Identifying information about your application.
- */
-public class DbxAppInfo extends Dumpable {
- private final String key;
- private final String secret;
- private final DbxHost host;
-
- /**
- * @param key Dropbox app key (see {@link #getKey})
- * @param secret Dropbox app secret (see {@link #getSecret})
- */
- public DbxAppInfo(String key, String secret) {
- checkKeyArg(key);
- checkSecretArg(secret);
-
- this.key = key;
- this.secret = secret;
- this.host = DbxHost.DEFAULT;
- }
-
- /**
- * @param key Dropbox app key (see {@link #getKey})
- * @param secret Dropbox app secret (see {@link #getSecret})
- * @param host Dropbox host configuration (see {@link #getHost})
- */
- public DbxAppInfo(String key, String secret, DbxHost host) {
- checkKeyArg(key);
- checkSecretArg(secret);
-
- this.key = key;
- this.secret = secret;
- this.host = host;
- }
-
- /**
- * Returns the Dropbox app key (OAuth calls this the consumer key). You can
- * create an app key and secret on the Dropbox
- * developer website.
- *
- * @return Dropbox app key
- */
- public String getKey() {
- return key;
- }
-
- /**
- * Returns the Dropbox app secret (OAuth calls this the consumer secret). You
- * can create an app key and secret on the Dropbox
- * developer website.
- *
- *
Make sure that this is kept a secret. Someone with your app secret can impesonate your
- * application. People sometimes ask for help on the Dropbox API forums and copy/paste their
- * code, which sometimes includes their app secret. Do not do that.
This is almost always {@link DbxHost#DEFAULT}. Typically this value will only be
- * different for testing purposes.
- *
- * @return Dropbox host configuration
- */
- public DbxHost getHost() {
- return host;
- }
-
- @Override
- protected void dumpFields(DumpWriter out) {
- out.f("key").v(key);
- out.f("secret").v(secret);
- }
-
- /**
- * If they key's format looks correct, return {@code null}. Otherwise return
- * a string that describes what the problem is.
- *
- *
- * NOTE: This function only performs some cursory checks on the format of the key.
- * Even if it returns {@code null} (which means "no problem"), it doesn't mean
- * that what you passed in is an actual valid Dropbox API app key.
- *
- */
- public static /*@Nullable*/String getKeyFormatError(String key) {
- return getTokenPartError(key);
- }
-
- /**
- * If they secret's format looks correct, return {@code null}. Otherwise return
- * a string that describes what the problem is.
- *
- *
- * NOTE: This function only performs some cursory checks on the format. Even if it
- * returns {@code null} (which means "no problem"), it doesn't mean that what
- * you passed in is an actual valid Dropbox API app key.
- *
- */
- public static /*@Nullable*/String getSecretFormatError(String key) {
- return getTokenPartError(key);
- }
-
- // ------------------------------------------------------
- // JSON parsing
-
- public static final JsonReader Reader = new JsonReader()
- {
- @Override
- public final DbxAppInfo read(JsonParser parser)
- throws IOException, JsonReadException
- {
- JsonLocation top = JsonReader.expectObjectStart(parser);
-
- String key = null;
- String secret = null;
- DbxHost host = null;
-
- while (parser.getCurrentToken() == JsonToken.FIELD_NAME) {
- String fieldName = parser.getCurrentName();
- parser.nextToken();
-
- try {
- if (fieldName.equals("key")) {
- key = KeyReader.readField(parser, fieldName, key);
- }
- else if (fieldName.equals("secret")) {
- secret = SecretReader.readField(parser, fieldName, secret);
- }
- else if (fieldName.equals("host")) {
- host = DbxHost.Reader.readField(parser, fieldName, host);
- }
- else {
- // Unknown field. Skip over it.
- JsonReader.skipValue(parser);
- }
- }
- catch (JsonReadException ex) {
- throw ex.addFieldContext(fieldName);
- }
- }
-
- JsonReader.expectObjectEnd(parser);
-
- if (key == null) throw new JsonReadException("missing field \"key\"", top);
- if (secret == null) throw new JsonReadException("missing field \"secret\"", top);
- if (host == null) host = DbxHost.DEFAULT;
-
- return new DbxAppInfo(key, secret, host);
- }
- };
-
- public static final JsonReader KeyReader = new JsonReader()
- {
- @Override
- public String read(JsonParser parser) throws IOException, JsonReadException
- {
- try {
- String v = parser.getText();
- String error = getKeyFormatError(v);
- if (error != null) {
- throw new JsonReadException("bad format for app key: " + error, parser.getTokenLocation());
- }
- parser.nextToken();
- return v;
- }
- catch (JsonParseException ex) {
- throw JsonReadException.fromJackson(ex);
- }
- }
- };
-
- public static final JsonReader SecretReader = new JsonReader()
- {
- @Override
- public String read(JsonParser parser) throws IOException, JsonReadException
- {
- try {
- String v = parser.getText();
- String error = getKeyFormatError(v);
- if (error != null) {
- throw new JsonReadException("bad format for app secret: " + error, parser.getTokenLocation());
- }
- parser.nextToken();
- return v;
- }
- catch (JsonParseException ex) {
- throw JsonReadException.fromJackson(ex);
- }
- }
-
- };
-
- public static /*@Nullable*/String getTokenPartError(String s)
- {
- if (s == null) return "can't be null";
- if (s.length() == 0) return "can't be empty";
- for (int i = 0; i < s.length(); i++) {
- char c = s.charAt(i);
- if (c < 0x21 || c > 0x7e) {
- // Only allow normal visible ASCII characters.
- return "invalid character at index " + i + ": " + jq("" + c);
- }
- }
- return null;
- }
-
- public static void checkKeyArg(String key)
- {
- String error = getTokenPartError(key);
- if (error == null) return;
- throw new IllegalArgumentException("Bad 'key': " + error);
- }
-
- public static void checkSecretArg(String secret)
- {
- String error = getTokenPartError(secret);
- if (error == null) return;
- throw new IllegalArgumentException("Bad 'secret': " + error);
- }
-}
diff --git a/src/autosaveworld/zlibs/com/dropbox/core/DbxException.java b/src/autosaveworld/zlibs/com/dropbox/core/DbxException.java
deleted file mode 100644
index 3e736953..00000000
--- a/src/autosaveworld/zlibs/com/dropbox/core/DbxException.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package autosaveworld.zlibs.com.dropbox.core;
-
-/**
- * The base exception thrown by Dropbox API calls. Normally, you'll need to do something specific
- * for {@link InvalidAccessTokenException} and possibly for {@link RetryException}. The rest you
- * should probably just log and investigate manually.
- */
-public class DbxException extends Exception {
- private static final long serialVersionUID = 0L;
-
- private final String requestId;
-
- public DbxException(String message) {
- this(null, message);
- }
-
- public DbxException(String requestId, String message) {
- super(message);
- this.requestId = requestId;
- }
-
- public DbxException(String message, Throwable cause) {
- this(null, message, cause);
- }
-
- public DbxException(String requestId, String message, Throwable cause) {
- super(message, cause);
- this.requestId = requestId;
- }
-
- /**
- * Return the unique ID associated with the request that triggered this exception.
- *
- *
The ID may be {@code null} if we could not receive a response from the Dropbox servers
- * (e.g. from a {@link NetworkIOException}).
- *
- *
Please use this ID when filing bug reports.
- *
- * @return unique ID associated with the request that caused this exception, or {@code null} if
- * one is not available.
- */
- public String getRequestId() {
- return requestId;
- }
-}
diff --git a/src/autosaveworld/zlibs/com/dropbox/core/DbxHost.java b/src/autosaveworld/zlibs/com/dropbox/core/DbxHost.java
deleted file mode 100644
index 600a75de..00000000
--- a/src/autosaveworld/zlibs/com/dropbox/core/DbxHost.java
+++ /dev/null
@@ -1,200 +0,0 @@
-package autosaveworld.zlibs.com.dropbox.core;
-
-import java.io.IOException;
-import java.util.Arrays;
-
-import autosaveworld.zlibs.com.dropbox.core.json.JsonReadException;
-import autosaveworld.zlibs.com.dropbox.core.json.JsonReader;
-import autosaveworld.zlibs.com.dropbox.core.json.JsonWriter;
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonGenerator;
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonLocation;
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonParser;
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonToken;
-
-/*>>> import checkers.nullness.quals.Nullable; */
-
-/**
- * This is for mocking things out during testing. Most of the time you won't have to deal with
- * this class; just use the default value: {@link DbxHost#DEFAULT}.
- */
-public final class DbxHost {
- /**
- * The standard Dropbox hosts: "api.dropbox.com", "api-content.dropbox.com",
- * and "www.dropbox.com"
- */
- public static final DbxHost DEFAULT = new DbxHost(
- "api.dropboxapi.com",
- "content.dropboxapi.com",
- "www.dropbox.com",
- "notify.dropboxapi.com"
- );
-
- private final String api;
- private final String content;
- private final String web;
- private final String notify;
-
- /**
- * @param api main Dropbox API server host name
- * @param content Dropbox API content server host name
- * @param web Dropbox web server host name
- * @param notify Dropbox notification server host name
- */
- public DbxHost(String api, String content, String web, String notify) {
- this.api = api;
- this.content = content;
- this.web = web;
- this.notify = notify;
- }
-
- /**
- * Returns the host name of the main Dropbox API server.
- * The default is {@code "api.dropbox.com"}.
- *
- * @return host name of main Dropbox API server
- */
- public String getApi() {
- return api;
- }
-
- /**
- * Returns the host name of the Dropbox API content server.
- * The default is {@code "api-content.dropbox.com"}.
- *
- * @return host name of Dropbox API content server
- */
- public String getContent() {
- return content;
- }
-
- /**
- * Returns the host name of the Dropbox web server. Used during user authorization.
- * The default is {@code "www.dropbox.com"}.
- *
- * @return host name of Dropbox API web server used during user authorization
- */
- public String getWeb() {
- return web;
- }
-
- /**
- * Returns the host name of the Dropbox notification server. Used by longpoll endpoints.
- * The default is {@code "api-notify.dropbox.com"}.
- *
- * @return host name of Dropbox notification server used for longpolling
- */
- public String getNotify() {
- return notify;
- }
-
- @Override
- public int hashCode() {
- return Arrays.hashCode(new String [] {api, content, web, notify});
- }
-
- @Override
- public boolean equals(/*@Nullable*/Object obj) {
- if (obj == this) {
- return true;
- } else if(obj instanceof DbxHost) {
- DbxHost other = (DbxHost) obj;
- return other.api.equals(this.api)
- && other.content.equals(this.content)
- && other.web.equals(this.web)
- && other.notify.equals(this.notify);
- } else {
- return false;
- }
- }
-
- private static DbxHost fromBaseHost(String s) {
- return new DbxHost("api-" + s, "api-content-" + s, "meta-" + s, "api-notify-" + s);
- }
-
- public static final JsonReader Reader = new JsonReader() {
- @Override
- public DbxHost read(JsonParser parser) throws IOException, JsonReadException {
- JsonToken t = parser.getCurrentToken();
- if (t == JsonToken.VALUE_STRING) {
- String s = parser.getText();
- JsonReader.nextToken(parser);
- return DbxHost.fromBaseHost(s);
- } else if (t == JsonToken.START_OBJECT) {
- JsonLocation top = parser.getTokenLocation();
- nextToken(parser);
-
- String api = null;
- String content = null;
- String web = null;
- String notify = null;
-
- while (parser.getCurrentToken() == JsonToken.FIELD_NAME) {
- String fieldName = parser.getCurrentName();
- parser.nextToken();
-
- try {
- if (fieldName.equals("api")) {
- api = JsonReader.StringReader.readField(parser, fieldName, api);
- }
- else if (fieldName.equals("content")) {
- content = JsonReader.StringReader.readField(parser, fieldName, content);
- }
- else if (fieldName.equals("web")) {
- web = JsonReader.StringReader.readField(parser, fieldName, web);
- }
- else if (fieldName.equals("notify")) {
- notify = JsonReader.StringReader.readField(parser, fieldName, notify);
- }
- else {
- throw new JsonReadException("unknown field", parser.getCurrentLocation());
- }
- }
- catch (JsonReadException ex) {
- throw ex.addFieldContext(fieldName);
- }
- }
-
- JsonReader.expectObjectEnd(parser);
-
- if (api == null) throw new JsonReadException("missing field \"api\"", top);
- if (content == null) throw new JsonReadException("missing field \"content\"", top);
- if (web == null) throw new JsonReadException("missing field \"web\"", top);
- if (notify == null) throw new JsonReadException("missing field \"notify\"", top);
-
- return new DbxHost(api, content, web, notify);
- } else {
- throw new JsonReadException("expecting a string or an object", parser.getTokenLocation());
- }
- }
- };
-
- private /*@Nullable*/String inferBaseHost() {
- if (web.startsWith("meta-") && api.startsWith("api-") && content.startsWith("api-content-") && notify.startsWith("api-notify-")) {
- String webBase = web.substring("meta-".length());
- String apiBase = api.substring("api-".length());
- String contentBase = content.substring("api-content-".length());
- String notifyBase = notify.substring("api-notify-".length());
- if (webBase.equals(apiBase) && webBase.equals(contentBase) && webBase.equals(notifyBase)) {
- return webBase;
- }
- }
- return null;
- }
-
- public static final JsonWriter Writer = new JsonWriter() {
- @Override
- public void write(DbxHost host, JsonGenerator g) throws IOException {
- String base = host.inferBaseHost();
- if (base != null) {
- g.writeString(base);
- } else {
- g.writeStartObject();
- g.writeStringField("api", host.api);
- g.writeStringField("content", host.content);
- g.writeStringField("web", host.web);
- g.writeStringField("notify", host.notify);
- g.writeEndObject();
- }
- }
- };
-}
diff --git a/src/autosaveworld/zlibs/com/dropbox/core/DbxRequestConfig.java b/src/autosaveworld/zlibs/com/dropbox/core/DbxRequestConfig.java
deleted file mode 100644
index b51f3f91..00000000
--- a/src/autosaveworld/zlibs/com/dropbox/core/DbxRequestConfig.java
+++ /dev/null
@@ -1,396 +0,0 @@
-package autosaveworld.zlibs.com.dropbox.core;
-
-import java.util.Locale;
-
-import autosaveworld.zlibs.com.dropbox.core.http.HttpRequestor;
-import autosaveworld.zlibs.com.dropbox.core.http.StandardHttpRequestor;
-
-/*>>> import checkers.nullness.quals.Nullable; */
-
-/**
- * A grouping of a few configuration parameters for how we should make requests to the
- * Dropbox servers.
- */
-public class DbxRequestConfig {
- private final String clientIdentifier;
- private final /*@Nullable*/String userLocale;
- private final HttpRequestor httpRequestor;
- private final int maxRetries;
-
- private DbxRequestConfig(String clientIdentifier, /*@Nullable*/ String userLocale, HttpRequestor httpRequestor, int maxRetries) {
- if (clientIdentifier == null) throw new NullPointerException("clientIdentifier");
- if (httpRequestor == null) throw new NullPointerException("httpRequestor");
- if (maxRetries < 0) throw new IllegalArgumentException("maxRetries");
-
- this.clientIdentifier = clientIdentifier;
- this.userLocale = toLanguageTag(userLocale);
- this.httpRequestor = httpRequestor;
- this.maxRetries = maxRetries;
- }
-
- /**
- * Creates a new configuration.
- *
- * @param clientIdentifier client identifier typically in the form "Name/Version" to be used in
- * the User-Agent header (see {@link #getClientIdentifier}).
- */
- public DbxRequestConfig(String clientIdentifier) {
- this(clientIdentifier, null);
- }
-
- /**
- * Creates a new configuration.
- *
- * @param clientIdentifier client identifier typically in the form "Name/Version" to be used in
- * the User-Agent header (see {@link #getClientIdentifier}).
- * @param userLocale IETF BCP 47 language tag of locale to use for user-visible text in responses, or
- * {@code null} to use the user's Dropbox locale preference.
- *
- * @deprecated Use {@link #newBuilder} to customize configuration
- */
- @Deprecated
- public DbxRequestConfig(String clientIdentifier, /*@Nullable*/ String userLocale) {
- this(clientIdentifier, userLocale, StandardHttpRequestor.INSTANCE);
- }
-
- /**
- * Creates a new configuration.
- *
- * @param clientIdentifier client identifier typically in the form "Name/Version" to be used in
- * the User-Agent header (see {@link #getClientIdentifier}).
- * @param userLocale IETF BCP 47 language tag of locale to use for user-visible text in responses, or
- * {@code null} to use the user's Dropbox locale preference.
- * @param httpRequestor HTTP client to use for issuing requests.
- *
- * @deprecated Use {@link #newBuilder} to customize configuration
- */
- @Deprecated
- public DbxRequestConfig(String clientIdentifier, /*@Nullable*/ String userLocale, HttpRequestor httpRequestor) {
- this(clientIdentifier, userLocale, httpRequestor, 0);
- }
-
- /**
- * Returns an identifier for the API client, typically of the form "Name/Version".
- * This is used to set the HTTP {@code User-Agent} header when making API requests.
- * Example: {@code "PhotoEditServer/1.3"}
- *
- *
- * If you're the author a higher-level library on top of the basic SDK, and the
- * "Photo Edit" Android app is using your library to access Dropbox, you should append
- * your library's name and version to form the full identifier. For example,
- * if your library is called "File Picker", you might set this field to:
- * {@code "PhotoEditAndroid/2.4 FilePicker/0.1-beta"}
- *
- * Note that the underlying {@link autosaveworld.zlibs.com.dropbox.core.http.HttpRequestor HttpRequestor} may
- * append other things to the {@code User-Agent}, such as the name of the library being used to
- * actually make the HTTP request, or the version of the Java VM.
- *
- *
- * @return HTTP User-Agent identifier for the API client
- */
- public String getClientIdentifier() {
- return clientIdentifier;
- }
-
- /**
- * Returns the locale of the user of your app as an IETF BCP 47 language tag. This is used by
- * the Dropbox server to localize user-visible strings returned by API calls.
- *
- *
If the value is {@code null} or some locale that Dropbox doesn't support, the strings
- * will be localized based on the user's Dropbox locale preference.
- *
- *
Defaults to {@code null}.
- *
- * @return locale of app user, or {@code null} to use user's Dropbox locale settings.
- */
- public String getUserLocale() {
- return userLocale;
- }
-
- /**
- * The {@link HttpRequestor} implementation to use when making HTTP requests to the Dropbox API
- * servers.
- *
- *
Defaults to {@link StandardHttpRequestor#INSTANCE}.
- *
- * @return HTTP requestor to use for issuing HTTP requests.
- */
- public HttpRequestor getHttpRequestor() {
- return httpRequestor;
- }
-
- /**
- * Returns whether or not the client should automatically retry RPC and download requests after
- * recieving a {@link RetryException}.
- *
- *
If enabled, the client will retry the request a max number of times (specified by {@link
- * #getMaxRetries}) before propagating the {@link RetryException}.
- *
- *
Defaults to {@code false} (the client will not automatically retry any requests).
- *
- * @return whether this client will automatically retry requests that fail with a {@link
- * RetryException}
- */
- public boolean isAutoRetryEnabled() {
- return maxRetries > 0;
- }
-
- /**
- * Returns the maximum number of times the client should automatically retry RPC and download
- * requests that fail with a {@link RetryException}.
- *
- *
This value does not count the initial request attempt. For example, if maximum retries is
- * 3, the client may issue a request a total of 4 times: once for the initial call, then 3
- * additional times for the 3 retries.
- *
- *
This value is ignored unless {@link #isAutoRetryEnabled} is {@code true}.
- *
- *
The value returned by this method is always positive if retries are enabled, otherwise it
- * is {@code 0}.
- *
- *
Defaults to {@code 3} when retries are enabled.
- *
- * @return maximum number of times the client will retry a request that throws a {@link
- * RetryException}.
- */
- public int getMaxRetries() {
- return maxRetries;
- }
-
- /**
- * Returns a builder for building a copy of this configuration. Useful for modifying an existing
- * configuration.
- *
- * @return builder configured to build a copy of this instance
- */
- public Builder copy() {
- return new Builder(clientIdentifier, userLocale, httpRequestor, maxRetries);
- }
-
-
- /**
- * Returns a new builder for creating a {@link DbxRequestConfig} instance.
- *
- * Identifiers are typically of the form "Name/Version" (e.g. {@code
- * "PhotoEditServer/1.3"}). See {@link #getClientIdentifier} for more details.
- *
- * @param clientIdentifier HTTP User-Agent identifier for the API app (see {@link
- * #getClientIdentifier}), never {@code null}
- */
- public static Builder newBuilder(String clientIdentifier) {
- if (clientIdentifier == null) throw new NullPointerException("clientIdentifier");
- return new Builder(clientIdentifier);
- }
-
- // Available in Java 7, but not in Java 6. Do a hacky version of it here.
- private static String toLanguageTag(Locale locale) {
- if (locale == null) {
- return null;
- }
- StringBuilder tag = new StringBuilder();
-
- tag.append(locale.getLanguage().toLowerCase());
-
- if (!locale.getCountry().isEmpty()) {
- tag.append("-");
- tag.append(locale.getCountry().toUpperCase());
- }
-
- return tag.toString();
- }
-
- // APIv1 accepts Locale.toString() formatted locales (e.g. 'en_US'), but APIv2 will return an
- // error if the locale is not in proper Language Tag format. Attempt to convert old locale
- // formats to the new one.
- private static String toLanguageTag(String locale) {
- if (locale == null) {
- return null;
- }
- // assume we are already a language tag
- if (!locale.contains("_")) {
- return locale;
- }
-
- // language can be missing, in which case we don't even bother
- if (locale.startsWith("_")) {
- return locale;
- }
-
- // Java 6 does "lang_country_variant". If country is missing, then "lang__variant". If no
- // variant, then just "lang_country".
- String [] parts = locale.split("_", 3);
-
- String lang = parts[0];
- String country = parts[1];
- String variant = parts.length == 3 ? parts[2] : "";
-
- return toLanguageTag(new Locale(lang, country, variant));
- }
-
- /**
- * Builder for {@link DbxRequestConfig}.
- */
- public static final class Builder {
- private final String clientIdentifier;
-
- private /*@Nullable*/ String userLocale;
- private HttpRequestor httpRequestor;
- private int maxRetries;
-
- private Builder(String clientIdentifier,
- /*@Nullable*/ String userLocale,
- HttpRequestor httpRequestor,
- int maxRetries) {
- this.clientIdentifier = clientIdentifier;
- this.userLocale = userLocale;
- this.httpRequestor = httpRequestor;
- this.maxRetries = maxRetries;
- }
-
- private Builder(String clientIdentifier) {
- this.clientIdentifier = clientIdentifier;
-
- this.userLocale = null;
- this.httpRequestor = StandardHttpRequestor.INSTANCE;
- this.maxRetries = 0;
- }
-
- /**
- * Set the locale of the app user. User-visible messages returned by the Dropbox servers
- * will be localized to this locale.
- *
- *
Defaults to {@code null}, which means strings will be localized according to the
- * user's Dropbox locale preference.
- *
- * @param userLocale locale of app user as an IETF BCP 47 language tag, or {@code null} to
- * use the user's Dropbox locale settings.
- *
- * @return this builder
- */
- public Builder withUserLocale(/*@Nullable*/ String userLocale) {
- this.userLocale = userLocale;
- return this;
- }
-
- /**
- * Set the locale of user-visible messages returned by the Dropbox servers to the user's
- * Dropbox locale.
- *
- *
User-visible strings will be localized according to the user's Dropbox locale
- * preference.
- *
- * @return this builder
- */
- public Builder withUserLocaleFromPreferences() {
- this.userLocale = null;
- return this;
- }
-
- /**
- * Set the locale of the app user. User-visible messages returned by the Dropbox servers
- * will be localized to this locale.
- *
- *
Defaults to {@code null}, which means strings will be localized according to the
- * user's Dropbox locale preference.
- *
- * @param userLocale Locale of app user, or {@code null} to use user's Dropbox locale settings.
- *
- * @return this builder
- */
- public Builder withUserLocaleFrom(/*@Nullable*/ Locale userLocale) { // not named withUserLocale because of ambiguous calls when passing 'null'
- this.userLocale = toLanguageTag(userLocale);
- return this;
- }
-
- /**
- * Set the HTTP requestor to use for issuing network requests to the Dropbox servers.
- *
- *
Defaults to {@link StandardHttpRequestor#INSTANCE}.
- *
- * @param httpRequestor HTTP requestor to use for network requests, never {@code null}
- *
- * @return this builder
- */
- public Builder withHttpRequestor(HttpRequestor httpRequestor) {
- if (httpRequestor == null) throw new NullPointerException("httpRequestor");
- this.httpRequestor = httpRequestor;
- return this;
- }
-
- /**
- * Enables automatic retry of RPC and download requests that fail with a {@link
- * RetryException}.
- *
- *
The default number of {@code 3} retries will be used in addition to the initial
- * request. To specify the maximum number of retries, see {@link
- * #withAutoRetryEnabled(int)}.
- *
- *
By default, the client will not automatically retry any requests.
- *
- * @return this builder
- */
- public Builder withAutoRetryEnabled() {
- return withAutoRetryEnabled(3);
- }
-
- /**
- * Disables automatic retry of RPC and download requests that fail with a {@link
- * RetryException}.
- *
- *
By default, the client will not automatically retry any requests.
- *
- * @return this builder
- *
- * @see #withAutoRetryEnabled
- */
- public Builder withAutoRetryDisabled() {
- this.maxRetries = 0;
- return this;
- }
-
- /**
- * Enables automatic retry of RPC and download requests that fail with a {@link
- * RetryException}.
- *
- *
The client will retry failed requests a maximum of {@code maxRetries} times before
- * propogating the exception. Note that {@code maxRetries} does not count the initial
- * request attempt. For example, if {@code maxRetries} is 3, the client may issue a request
- * a total of 4 times: once for the initial call, then 3 additional times for the 3
- * retries.
- *
- *
By default, the client will not automatically retry any requests.
- *
- *
To enable automatic retries with the default maximum number of attempts, use {@link
- * #withAutoRetryEnabled()}.
- *
- * @param maxRetries maximum number of times to retry a retriable failed request. Must be
- * positive.
- *
- * @return this builder
- *
- * @throws IllegalArgumentException if {@code maxRetries} is not positive.
- */
- public Builder withAutoRetryEnabled(int maxRetries) {
- if (maxRetries <= 0) throw new IllegalArgumentException("maxRetries must be positive");
- this.maxRetries = maxRetries;
- return this;
- }
-
- /**
- * Builds an instance of {@link DbxRequestConfig} with this builder's configured parameters
- * or defaults.
- *
- * @return new {@code DbxRequestConfig} instance.
- */
- public DbxRequestConfig build() {
- return new DbxRequestConfig(clientIdentifier, userLocale, httpRequestor, maxRetries);
- }
- }
-}
diff --git a/src/autosaveworld/zlibs/com/dropbox/core/DbxRequestUtil.java b/src/autosaveworld/zlibs/com/dropbox/core/DbxRequestUtil.java
deleted file mode 100644
index fa0dbfb5..00000000
--- a/src/autosaveworld/zlibs/com/dropbox/core/DbxRequestUtil.java
+++ /dev/null
@@ -1,459 +0,0 @@
-package autosaveworld.zlibs.com.dropbox.core;
-
-import static autosaveworld.zlibs.com.dropbox.core.util.LangUtil.mkAssert;
-import static autosaveworld.zlibs.com.dropbox.core.util.StringUtil.jq;
-
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URLEncoder;
-import java.nio.charset.CharacterCodingException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Random;
-import java.util.concurrent.TimeUnit;
-
-import autosaveworld.zlibs.com.dropbox.core.http.HttpRequestor;
-import autosaveworld.zlibs.com.dropbox.core.json.JsonReadException;
-import autosaveworld.zlibs.com.dropbox.core.json.JsonReader;
-import autosaveworld.zlibs.com.dropbox.core.util.IOUtil;
-import autosaveworld.zlibs.com.dropbox.core.util.StringUtil;
-
-/*>>> import checkers.nullness.quals.Nullable; */
-
-public final class DbxRequestUtil {
- private static final Random RAND = new Random();
-
- public static String encodeUrlParam(String s) {
- try {
- return URLEncoder.encode(s, "UTF-8");
- } catch (UnsupportedEncodingException ex) {
- throw mkAssert("UTF-8 should always be supported", ex);
- }
- }
-
- public static String buildUrlWithParams(/*@Nullable*/String userLocale,
- String host,
- String path,
- /*@Nullable*/String/*@Nullable*/[] params) {
- return buildUri(host, path) + "?" + encodeUrlParams(userLocale, params);
- }
-
- static String [] toParamsArray(Map params) {
- String [] arr = new String[2 * params.size()];
- int i = 0;
- for (Map.Entry entry : params.entrySet()) {
- arr[i] = entry.getKey();
- arr[i + 1] = entry.getValue();
- i += 2;
- }
- return arr;
- }
-
- public static String buildUri(String host, String path) {
- try {
- return new URI("https", host, "/" + path, null).toASCIIString();
- }
- catch (URISyntaxException ex) {
- throw mkAssert("URI creation failed, host=" + jq(host) + ", path=" + jq(path), ex);
- }
- }
-
- private static String encodeUrlParams(/*@Nullable*/String userLocale,
- /*@Nullable*/String/*@Nullable*/[] params) {
- StringBuilder buf = new StringBuilder();
- String sep = "";
- if (userLocale != null) {
- buf.append("locale=").append(userLocale);
- sep = "&";
- }
-
- if (params != null) {
- if (params.length % 2 != 0) {
- throw new IllegalArgumentException("'params.length' is " + params.length + "; expecting a multiple of two");
- }
- for (int i = 0; i < params.length; ) {
- String key = params[i];
- String value = params[i+1];
- if (key == null) throw new IllegalArgumentException("params[" + i + "] is null");
- if (value != null) {
- buf.append(sep); sep = "&";
- buf.append(encodeUrlParam(key));
- buf.append("=");
- buf.append(encodeUrlParam(value));
- }
- i += 2;
- }
- }
-
- return buf.toString();
- }
-
- public static List addAuthHeader(/*@Nullable*/List headers, String accessToken) {
- if (accessToken == null) throw new NullPointerException("accessToken");
- if (headers == null) headers = new ArrayList();
-
- headers.add(new HttpRequestor.Header("Authorization", "Bearer " + accessToken));
- return headers;
- }
-
- public static List addSelectUserHeader(/*@Nullable*/List headers, String memberId) {
- if (memberId == null) throw new NullPointerException("memberId");
- if (headers == null) headers = new ArrayList();
-
- headers.add(new HttpRequestor.Header("Dropbox-API-Select-User", memberId));
- return headers;
- }
-
- public static List addBasicAuthHeader(/*@Nullable*/List headers, String username, String password) {
- if (username == null) throw new NullPointerException("username");
- if (password == null) throw new NullPointerException("password");
- if (headers == null) headers = new ArrayList();
-
- String credentials = username + ":" + password;
- String base64Credentials = StringUtil.base64Encode(StringUtil.stringToUtf8(credentials));
- headers.add(new HttpRequestor.Header("Authorization", "Basic " + base64Credentials));
- return headers;
- }
-
- public static List addUserAgentHeader(
- /*@Nullable*/List headers,
- DbxRequestConfig requestConfig,
- String sdkUserAgentIdentifier
- ) {
- if (headers == null) headers = new ArrayList();
- headers.add(buildUserAgentHeader(requestConfig, sdkUserAgentIdentifier));
- return headers;
- }
-
- public static List addUserLocaleHeader(/*@Nullable*/List headers, DbxRequestConfig requestConfig) {
- if (requestConfig.getUserLocale() == null) {
- return headers;
- }
-
- if (headers == null) headers = new ArrayList();
- headers.add(new HttpRequestor.Header("Dropbox-API-User-Locale", requestConfig.getUserLocale()));
- return headers;
- }
-
- public static HttpRequestor.Header buildUserAgentHeader(DbxRequestConfig requestConfig, String sdkUserAgentIdentifier) {
- return new HttpRequestor.Header("User-Agent", requestConfig.getClientIdentifier() + " " + sdkUserAgentIdentifier + "/" + "ASW 1.0 (JSDK 2.1.2)");
- }
-
- /**
- * Convenience function for making HTTP GET requests.
- */
- public static HttpRequestor.Response startGet(DbxRequestConfig requestConfig,
- String accessToken,
- String sdkUserAgentIdentifier,
- String host,
- String path,
- /*@Nullable*/String/*@Nullable*/[] params,
- /*@Nullable*/List headers)
- throws NetworkIOException {
- headers = copyHeaders(headers);
- headers = addUserAgentHeader(headers, requestConfig, sdkUserAgentIdentifier);
- headers = addAuthHeader(headers, accessToken);
-
- String url = buildUrlWithParams(requestConfig.getUserLocale(), host, path, params);
- try {
- return requestConfig.getHttpRequestor().doGet(url, headers);
- }
- catch (IOException ex) {
- throw new NetworkIOException(ex);
- }
- }
-
- /**
- * Convenience function for making HTTP PUT requests.
- */
- public static HttpRequestor.Uploader startPut(DbxRequestConfig requestConfig,
- String accessToken,
- String sdkUserAgentIdentifier,
- String host, String path,
- /*@Nullable*/String/*@Nullable*/[] params,
- /*@Nullable*/List headers)
- throws NetworkIOException {
- headers = copyHeaders(headers);
- headers = addUserAgentHeader(headers, requestConfig, sdkUserAgentIdentifier);
- headers = addAuthHeader(headers, accessToken);
-
- String url = buildUrlWithParams(requestConfig.getUserLocale(), host, path, params);
- try {
- return requestConfig.getHttpRequestor().startPut(url, headers);
- }
- catch (IOException ex) {
- throw new NetworkIOException(ex);
- }
- }
-
- /**
- * Convenience function for making HTTP POST requests.
- */
- public static HttpRequestor.Response startPostNoAuth(DbxRequestConfig requestConfig,
- String sdkUserAgentIdentifier,
- String host,
- String path,
- /*@Nullable*/String/*@Nullable*/[] params,
- /*@Nullable*/List headers)
- throws NetworkIOException {
- byte[] encodedParams = StringUtil.stringToUtf8(encodeUrlParams(requestConfig.getUserLocale(), params));
-
- headers = copyHeaders(headers);
- headers.add(new HttpRequestor.Header("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"));
-
- return startPostRaw(requestConfig, sdkUserAgentIdentifier, host, path, encodedParams, headers);
- }
-
-
- /**
- * Convenience function for making HTTP POST requests. Like startPostNoAuth but takes byte[] instead of params.
- */
- public static HttpRequestor.Response startPostRaw(DbxRequestConfig requestConfig,
- String sdkUserAgentIdentifier,
- String host,
- String path,
- byte[] body,
- /*@Nullable*/List headers)
- throws NetworkIOException {
- String uri = buildUri(host, path);
-
- headers = copyHeaders(headers);
- headers = addUserAgentHeader(headers, requestConfig, sdkUserAgentIdentifier);
- headers.add(new HttpRequestor.Header("Content-Length", Integer.toString(body.length)));
-
- try {
- HttpRequestor.Uploader uploader = requestConfig.getHttpRequestor().startPost(uri, headers);
- try {
- uploader.upload(body);
- return uploader.finish();
- } finally {
- uploader.close();
- }
- } catch (IOException ex) {
- throw new NetworkIOException(ex);
- }
- }
-
- private static List copyHeaders(List headers) {
- if (headers == null) {
- return new ArrayList();
- } else {
- return new ArrayList(headers);
- }
- }
-
- public static byte[] loadErrorBody(HttpRequestor.Response response)
- throws NetworkIOException {
- if (response.getBody() == null) {
- return new byte[0];
- }
-
- // Slurp the body into memory (up to 4k; anything past that is probably not useful).
- try {
- return IOUtil.slurp(response.getBody(), 4096);
- } catch (IOException ex) {
- throw new NetworkIOException(ex);
- }
-
- }
-
- public static String parseErrorBody(String requestId, int statusCode, byte[] body)
- throws BadResponseException {
- // Read the error message from the body.
- // TODO: Get charset from the HTTP Content-Type header. It's wrong to just assume UTF-8.
- // TODO: Maybe try parsing the message as JSON and do something more structured?
- try {
- return StringUtil.utf8ToString(body);
- } catch (CharacterCodingException e) {
- throw new BadResponseException(requestId, "Got non-UTF8 response body: " + statusCode + ": " + e.getMessage());
- }
- }
-
- public static DbxException unexpectedStatus(HttpRequestor.Response response)
- throws NetworkIOException, BadResponseException {
- String requestId = getRequestId(response);
- byte[] body = loadErrorBody(response);
- String message = parseErrorBody(requestId, response.getStatusCode(), body);
-
- switch (response.getStatusCode()) {
- case 400:
- return new BadRequestException(requestId, message);
- case 401:
- return new InvalidAccessTokenException(requestId, message);
- case 429:
- try {
- int backoffSecs = Integer.parseInt(getFirstHeader(response, "Retry-After"));
- return new RateLimitException(requestId, message, backoffSecs, TimeUnit.SECONDS);
- } catch (NumberFormatException ex) {
- return new BadResponseException(requestId, "Invalid value for HTTP header: \"Retry-After\"");
- }
- case 500:
- return new ServerException(requestId, message);
- case 503:
- // API v1 may include Retry-After in 503 responses, v2 does not
- String retryAfter = getFirstHeaderMaybe(response, "Retry-After");
- try {
- if (retryAfter != null && !retryAfter.trim().isEmpty()) {
- int backoffSecs = Integer.parseInt(retryAfter);
- return new RetryException(requestId, message, backoffSecs, TimeUnit.SECONDS);
- } else {
- return new RetryException(requestId, message);
- }
- } catch (NumberFormatException ex) {
- return new BadResponseException(requestId, "Invalid value for HTTP header: \"Retry-After\"");
- }
- default:
- return new BadResponseCodeException(
- requestId,
- "unexpected HTTP status code: " + response.getStatusCode() + ": " + message,
- response.getStatusCode()
- );
- }
- }
-
- public static T readJsonFromResponse(JsonReader reader, HttpRequestor.Response response)
- throws BadResponseException, NetworkIOException {
- try {
- return reader.readFully(response.getBody());
- } catch (JsonReadException ex) {
- String requestId = getRequestId(response);
- throw new BadResponseException(requestId, "error in response JSON: " + ex.getMessage(), ex);
- } catch (IOException ex) {
- throw new NetworkIOException(ex);
- }
- }
-
- public static abstract class ResponseHandler {
- public abstract T handle(HttpRequestor.Response response) throws DbxException;
- }
-
- public static T doGet(final DbxRequestConfig requestConfig,
- final String accessToken,
- final String sdkUserAgentIdentifier,
- final String host,
- final String path,
- final /*@Nullable*/String/*@Nullable*/[] params,
- final /*@Nullable*/List headers,
- final ResponseHandler handler)
- throws DbxException {
- return runAndRetry(requestConfig.getMaxRetries(), new RequestMaker() {
- @Override
- public T run() throws DbxException {
- HttpRequestor.Response response = startGet(requestConfig, accessToken, sdkUserAgentIdentifier, host, path, params, headers);
- try {
- return handler.handle(response);
- } finally {
- try {
- response.getBody().close();
- } catch (IOException ex) {
- //noinspection ThrowFromFinallyBlock
- throw new NetworkIOException(ex);
- }
- }
- }
- });
- }
-
- public static T doPost(DbxRequestConfig requestConfig,
- String accessToken,
- String sdkUserAgentIdentifier,
- String host,
- String path,
- /*@Nullable*/String/*@Nullable*/[] params,
- /*@Nullable*/List headers,
- ResponseHandler handler)
- throws DbxException {
- headers = copyHeaders(headers);
- headers = addAuthHeader(headers, accessToken);
- return doPostNoAuth(requestConfig, sdkUserAgentIdentifier, host, path, params, headers, handler);
- }
-
- public static T doPostNoAuth(final DbxRequestConfig requestConfig,
- final String sdkUserAgentIdentifier,
- final String host,
- final String path,
- final /*@Nullable*/String/*@Nullable*/[] params,
- final /*@Nullable*/List headers,
- final ResponseHandler handler)
- throws DbxException {
- return runAndRetry(requestConfig.getMaxRetries(), new RequestMaker() {
- @Override
- public T run() throws DbxException {
- HttpRequestor.Response response = startPostNoAuth(requestConfig, sdkUserAgentIdentifier, host, path, params, headers);
- return finishResponse(response, handler);
- }
- });
- }
-
- public static T finishResponse(HttpRequestor.Response response, ResponseHandler handler) throws DbxException {
- try {
- return handler.handle(response);
- } finally {
- IOUtil.closeInput(response.getBody());
- }
- }
-
- public static String getFirstHeader(HttpRequestor.Response response, String name) throws BadResponseException {
- List values = response.getHeaders().get(name);
- if (values == null || values.isEmpty()) {
- throw new BadResponseException(getRequestId(response), "missing HTTP header \"" + name + "\"");
- }
- return values.get(0);
- }
-
- public static /*@Nullable*/String getFirstHeaderMaybe(HttpRequestor.Response response, String name) {
- List values = response.getHeaders().get(name);
- if (values == null || values.isEmpty()) {
- return null;
- }
- return values.get(0);
- }
-
- public static /*@Nullable*/ String getRequestId(HttpRequestor.Response response) {
- return DbxRequestUtil.getFirstHeaderMaybe(response, "X-Dropbox-Request-Id");
- }
-
- public static abstract class RequestMaker {
- public abstract T run() throws DbxException, E;
- }
-
- public static T runAndRetry(int maxRetries, RequestMaker requestMaker)
- throws DbxException, E {
- int numRetries = 0;
- while (true) {
- long backoff;
- DbxException thrown = null;
- try {
- return requestMaker.run();
- } catch (RetryException ex) {
- backoff = ex.getBackoffMillis();
- thrown = ex;
- } catch (ServerException ex) {
- backoff = 0L;
- thrown = ex;
- }
-
- if (numRetries >= maxRetries) {
- throw thrown;
- }
-
- // add a random jitter to the backoff to avoid stampeding herd. This is especially
- // useful for ServerExceptions, where backoff is 0.
- backoff += RAND.nextInt(1000);
-
- if (backoff > 0L) {
- try {
- Thread.sleep(backoff);
- } catch (InterruptedException ex) {
- // preserve interrupt
- Thread.currentThread().interrupt();
- }
- }
-
- ++numRetries;
- }
- }
-}
diff --git a/src/autosaveworld/zlibs/com/dropbox/core/DbxUploader.java b/src/autosaveworld/zlibs/com/dropbox/core/DbxUploader.java
deleted file mode 100644
index 53593386..00000000
--- a/src/autosaveworld/zlibs/com/dropbox/core/DbxUploader.java
+++ /dev/null
@@ -1,247 +0,0 @@
-package autosaveworld.zlibs.com.dropbox.core;
-
-import java.io.Closeable;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import autosaveworld.zlibs.com.dropbox.core.http.HttpRequestor;
-import autosaveworld.zlibs.com.dropbox.core.stone.StoneSerializer;
-import autosaveworld.zlibs.com.dropbox.core.util.IOUtil;
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonProcessingException;
-
-/**
- * Class for completing upload requests.
- *
- * This class provides methods for uploading a request body and handling the server response.
- *
- * Example usage:
- *
- *
- *
- * @param response type returned by server on request success
- * @param exception type returned by server on request failure
- */
-public abstract class DbxUploader implements Closeable {
- private final HttpRequestor.Uploader httpUploader;
- private final StoneSerializer responseSerializer;
- private final StoneSerializer errorSerializer;
-
- private boolean closed;
- private boolean finished;
-
- protected DbxUploader(HttpRequestor.Uploader httpUploader, StoneSerializer responseSerializer, StoneSerializer errorSerializer) {
- this.httpUploader = httpUploader;
- this.responseSerializer = responseSerializer;
- this.errorSerializer = errorSerializer;
-
- this.closed = false;
- this.finished = false;
- }
-
- protected abstract X newException(DbxWrappedException error);
-
- /**
- * Uploads all bytes read from the given {@link InputStream} and returns the response.
- *
- * This method manages closing this uploader's resources, so no further calls to {@link #close}
- * are necessary. The underlying {@code OutputStream} returned by {@link #getOutputStream}
- * will be closed by this method.
- *
- * This method is the equivalent of
- *
- *
- * try {
- * OutputStream out = uploader.getOutputStream();
- * // read from in, write to out
- * response = uploader.finish();
- * } finally {
- * uploader.close();
- * }
- *
- *
- * @param in {@code InputStream} containing data to upload
- *
- * @return Response from server
- *
- * @throws X if the server sent an error response for the request
- * @throws DbxException if an error occurs uploading the data or reading the response
- * @throws IOException if an error occurs reading the input stream.
- * @throws IllegalStateException if this uploader has already been closed (see {@link #close}) or finished (see {@link #finish})
- */
- public R uploadAndFinish(InputStream in) throws X, DbxException, IOException {
- try {
- try {
- httpUploader.upload(in);
- } catch (IOException ex) {
- // write exceptions and everything else is a Network I/O problem
- throw new NetworkIOException(ex);
- }
-
- return finish();
- } finally {
- close();
- }
- }
-
- /**
- * Uploads up to {@code limit} bytes read from the given {@link InputStream} and returns the
- * response.
- *
- * This method upload bytes from the given {@link InputStream} until {@code limit} bytes have
- * been read or end-of-stream is detected. Use {@link #uploadAndFinish(InputStream)} to upload the entire
- * stream.
- *
- * This method manages closing this uploader's resources, so no further calls to {@link #close}
- * are necessary. The underlying {@code OutputStream} returned by {@link #getOutputStream}
- * will be closed by this method.
- *
- * This method is the equivalent of
- *
- *
- * try {
- * OutputStream out = uploader.getOutputStream();
- * // read at most `limit` bytes from in, write to out
- * response = uploader.finish();
- * } finally {
- * uploader.close();
- * }
- *
- *
- * @param in {@code InputStream} containing data to upload
- * @param limit Maximum number of bytes to read from the given {@code InputStream}
- *
- * @return Response from server
- *
- * @throws X if the server sent an error response for the request
- * @throws DbxException if an error occurs uploading the data or reading the response
- * @throws IOException if an error occurs reading the input stream.
- * @throws IllegalStateException if this uploader has already been closed (see {@link #close}) or finished (see {@link #finish})
- */
- public R uploadAndFinish(InputStream in, long limit) throws X, DbxException, IOException {
- return uploadAndFinish(IOUtil.limit(in, limit));
- }
-
- /**
- * Closes this upload request and releases its underlying resources.
- *
- * This method should always be called to allow for proper resource deallocation.
- *
- *
- */
- @Override
- public void close() {
- if (!closed) {
- httpUploader.close();
- closed = true;
- }
- }
-
- /**
- * Aborts this upload request and closes its underlying connection.
- */
- public void abort() {
- httpUploader.abort();
- }
-
- /**
- * Returns an {@link OutputStream} that writes to the request body. Remember to call {@link
- * #finish} to complete the request and retrieve the response.
- *
- * Data writen to this stream will be uploaded.
- *
- * Typically you will not need this method and can use the more convenient {@link
- * #uploadAndFinish(InputStream)}.
- *
- * @return Request body output stream.
- *
- * @throws IllegalStateException if this uploader has already been closed (see {@link #close}) or finished (see {@link #finish})
- *
- * @see #uploadAndFinish(InputStream)
- */
- public OutputStream getOutputStream() {
- assertOpenAndUnfinished();
- return this.httpUploader.getBody();
- }
-
- /**
- * Completes the request and returns response from the server.
- *
- * This method should be called after writing data to the upload {@link OutputStream} (see
- * {@link #getOutputStream}).
- *
- * @return Response from server
- *
- * @throws X if the server sent an error response for the request
- * @throws DbxException if an error occurs sending the upload or reading the response
- * @throws IllegalStateException if this uploader has already been closed (see {@link #close}) or finished (see {@link #finish})
- */
- public R finish() throws X, DbxException {
- assertOpenAndUnfinished();
-
- HttpRequestor.Response response = null;
- try {
- response = httpUploader.finish();
-
- try {
- if (response.getStatusCode() == 200) {
- return responseSerializer.deserialize(response.getBody());
- }
- else if (response.getStatusCode() == 409) {
- DbxWrappedException wrapped = DbxWrappedException.fromResponse(errorSerializer, response);
- throw newException(wrapped);
- }
- else {
- throw DbxRequestUtil.unexpectedStatus(response);
- }
- } catch (JsonProcessingException ex) {
- String requestId = DbxRequestUtil.getRequestId(response);
- throw new BadResponseException(requestId, "Bad JSON in response: " + ex, ex);
- }
- } catch (IOException ex) {
- throw new NetworkIOException(ex);
- } finally {
- // Make sure input stream is closed
- if (response != null) {
- IOUtil.closeQuietly(response.getBody());
- }
- finished = true;
- }
- }
-
- private void assertOpenAndUnfinished() {
- if (closed) {
- throw new IllegalStateException("This uploader is already closed.");
- }
- if (finished) {
- throw new IllegalStateException("This uploader is already finished and cannot be used to upload more data.");
- }
- }
-}
diff --git a/src/autosaveworld/zlibs/com/dropbox/core/DbxWrappedException.java b/src/autosaveworld/zlibs/com/dropbox/core/DbxWrappedException.java
deleted file mode 100644
index bd1350c9..00000000
--- a/src/autosaveworld/zlibs/com/dropbox/core/DbxWrappedException.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package autosaveworld.zlibs.com.dropbox.core;
-
-import java.io.IOException;
-
-import autosaveworld.zlibs.com.dropbox.core.http.HttpRequestor;
-import autosaveworld.zlibs.com.dropbox.core.stone.StoneSerializer;
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonParseException;
-
-/**
- * For internal use only.
- */
-public final class DbxWrappedException extends Exception {
- private static final long serialVersionUID = 0L;
-
- private final Object errValue; // Really an ErrT instance, but Throwable does not allow generic subclasses.
- private final String requestId;
- private final LocalizedText userMessage;
-
- public DbxWrappedException(Object errValue, String requestId, LocalizedText userMessage) {
- this.errValue = errValue;
- this.requestId = requestId;
- this.userMessage = userMessage;
- }
-
- public Object getErrorValue() {
- return errValue;
- }
-
- public String getRequestId() {
- return requestId;
- }
-
- public LocalizedText getUserMessage() {
- return userMessage;
- }
-
- public static DbxWrappedException fromResponse(StoneSerializer errSerializer, HttpRequestor.Response response)
- throws IOException, JsonParseException {
- String requestId = DbxRequestUtil.getRequestId(response);
-
- ApiErrorResponse apiResponse = new ApiErrorResponse.Serializer(errSerializer)
- .deserialize(response.getBody());
-
- return new DbxWrappedException(apiResponse.getError(), requestId, apiResponse.getUserMessage());
- }
-}
diff --git a/src/autosaveworld/zlibs/com/dropbox/core/InvalidAccessTokenException.java b/src/autosaveworld/zlibs/com/dropbox/core/InvalidAccessTokenException.java
deleted file mode 100644
index def73939..00000000
--- a/src/autosaveworld/zlibs/com/dropbox/core/InvalidAccessTokenException.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package autosaveworld.zlibs.com.dropbox.core;
-
-/**
- * Gets thrown when the access token you're using to make API calls is invalid.
- *
- *
- * A more typical situation is that your access token was valid, but the
- * user has since "unlinked" your application via the Dropbox website
- * (http://www.dropbox.com/account#applications).
- * When a user unlinks your application, your access tokens for that user become
- * invalid. You can re-run the authorization process to obtain a new access token.
- *
- */
-public class InvalidAccessTokenException extends DbxException {
- private static final long serialVersionUID = 0;
-
- public InvalidAccessTokenException(String requestId, String message) {
- super(requestId, message);
- }
-}
diff --git a/src/autosaveworld/zlibs/com/dropbox/core/LocalizedText.java b/src/autosaveworld/zlibs/com/dropbox/core/LocalizedText.java
deleted file mode 100644
index bf07d348..00000000
--- a/src/autosaveworld/zlibs/com/dropbox/core/LocalizedText.java
+++ /dev/null
@@ -1,103 +0,0 @@
-package autosaveworld.zlibs.com.dropbox.core;
-
-import java.io.IOException;
-
-import autosaveworld.zlibs.com.dropbox.core.stone.StoneSerializer;
-import autosaveworld.zlibs.com.dropbox.core.stone.StoneSerializers;
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonGenerationException;
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonGenerator;
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonParseException;
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonParser;
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonToken;
-
-/**
- * Human-readable text localized to a specific locale.
- */
-public final class LocalizedText {
- private final String text;
- private final String locale;
-
- /**
- * Create a {@link LocalizedText} object that contains the given {@code text} already localized
- * to {@code locale}.
- *
- * @param text Localized, human-readable text. Must not be {@code null}
- * @param locale IETF BCP 47 language tag of text locale. Must not be {@code null}
- */
- public LocalizedText(String text, String locale) {
- if (text == null) {
- throw new NullPointerException("text");
- }
- if (locale == null) {
- throw new NullPointerException("locale");
- }
-
- this.text = text;
- this.locale = locale;
- }
-
- /**
- * Returns the localized, human-readable text.
- *
- * @return localized, human-readable text, never {@code null}
- */
- public String getText() {
- return text;
- }
-
- /**
- * Returns locale of the text in IETF BCP 47 language tag format.
- *
- * @return locale of text in IETF BCP 47 language tag format, never {@code null}
- */
- public String getLocale() {
- return locale;
- }
-
- @Override
- public String toString() {
- return text;
- }
-
- /**
- * For internal use only.
- */
- static final StoneSerializer STONE_SERIALIZER = new StoneSerializer() {
- @Override
- public void serialize(LocalizedText value, JsonGenerator g) throws IOException, JsonGenerationException {
- throw new UnsupportedOperationException("Error wrapper serialization not supported.");
- }
-
- @Override
- public LocalizedText deserialize(JsonParser p) throws IOException, JsonParseException {
- String text = null;
- String locale = null;
-
- expectStartObject(p);
- while (p.getCurrentToken() == JsonToken.FIELD_NAME) {
- String field = p.getCurrentName();
- p.nextToken();
- if ("text".equals(field)) {
- text = StoneSerializers.string().deserialize(p);
- } else if ("locale".equals(field)) {
- locale = StoneSerializers.string().deserialize(p);
- } else {
- skipValue(p);
- }
- }
-
- if (text == null) {
- throw new JsonParseException(p, "Required field \"text\" missing.");
- }
-
- if (locale == null) {
- throw new JsonParseException(p, "Required field \"locale\" missing.");
- }
-
- LocalizedText value = new LocalizedText(text, locale);
- expectEndObject(p);
-
- return value;
- }
- };
-}
diff --git a/src/autosaveworld/zlibs/com/dropbox/core/NetworkIOException.java b/src/autosaveworld/zlibs/com/dropbox/core/NetworkIOException.java
deleted file mode 100644
index 87b4d45b..00000000
--- a/src/autosaveworld/zlibs/com/dropbox/core/NetworkIOException.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package autosaveworld.zlibs.com.dropbox.core;
-
-import java.io.IOException;
-
-/**
- * This gets thrown when there's an {@link IOException} when reading or writing to the
- * network (when communicating with the Dropbox API servers).
- *
- *
We use a separate exception class (instead of just relaying {@code IOException}) to make it
- * easier for you to distinguish between I/O errors communicating with Dropbox and I/O errors from
- * your own code.
- */
-public class NetworkIOException extends DbxException {
- private static final long serialVersionUID = 0L;
-
- public NetworkIOException(IOException cause) {
- super(cause.getMessage(), cause);
- }
-
- @Override
- public IOException getCause() {
- // guaranteed to be an IOException
- return (IOException) super.getCause();
- }
-}
-
diff --git a/src/autosaveworld/zlibs/com/dropbox/core/ProtocolException.java b/src/autosaveworld/zlibs/com/dropbox/core/ProtocolException.java
deleted file mode 100644
index ea2bb89e..00000000
--- a/src/autosaveworld/zlibs/com/dropbox/core/ProtocolException.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package autosaveworld.zlibs.com.dropbox.core;
-
-/**
- * Something unexpected happened with either the request or the response.
- * This can happen if there's a bug in the client code (including this
- * library), if there's a bug in on the Dropbox server, or if Dropbox
- * made a change to the API that changed the behavior of something and
- * we haven't upgraded our SDK yet.
- *
- *
- * Typically, these kinds of exceptions should be logged, so you can
- * investigate later.
- *
- */
-public abstract class ProtocolException extends DbxException {
- private static final long serialVersionUID = 0;
-
- public ProtocolException(String requestId, String message) {
- super(requestId, message);
- }
-
- public ProtocolException(String requestId, String message, Throwable cause) {
- super(requestId, message, cause);
- }
-}
-
diff --git a/src/autosaveworld/zlibs/com/dropbox/core/RateLimitException.java b/src/autosaveworld/zlibs/com/dropbox/core/RateLimitException.java
deleted file mode 100644
index c1ec6ba6..00000000
--- a/src/autosaveworld/zlibs/com/dropbox/core/RateLimitException.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package autosaveworld.zlibs.com.dropbox.core;
-
-import java.util.concurrent.TimeUnit;
-
-/**
- * The server is overloaded, or you have hit a rate limit. Try again later after the designated
- * backoff (see {@link #getBackoffMillis}).
- */
-public class RateLimitException extends RetryException {
- private static final long serialVersionUID = 0L;
-
- public RateLimitException(String requestId, String message, long backoff, TimeUnit unit) {
- super(requestId, message, backoff, unit);
- }
-}
-
diff --git a/src/autosaveworld/zlibs/com/dropbox/core/RetryException.java b/src/autosaveworld/zlibs/com/dropbox/core/RetryException.java
deleted file mode 100644
index 2a784c87..00000000
--- a/src/autosaveworld/zlibs/com/dropbox/core/RetryException.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package autosaveworld.zlibs.com.dropbox.core;
-
-import java.util.concurrent.TimeUnit;
-
-/**
- * A transient exception has occurred and the request should be retried. Clients should only retry
- * requests after waiting the requested backoff duration (see {@link #getBackoffMillis}).
- */
-public class RetryException extends DbxException {
- private static final long serialVersionUID = 0L;
-
- private final long backoffMillis;
-
- /**
- * Creates an instance of this exception with no retry backoff.
- *
- * @param requestId ID assigned to request by Dropbox servers
- * @param message Error message
- */
- public RetryException(String requestId, String message) {
- this(requestId, message, 0L, TimeUnit.MILLISECONDS);
- }
-
- /**
- * Creates an instance of this exception with the given retry backoff.
- *
- * @param requestId ID assigned to request by Dropbox servers
- * @param message Error message
- * @param backoff amount of time to backoff before retrying the request
- * @param unit unit of time for {@code backoff}
- */
- public RetryException(String requestId, String message, long backoff, TimeUnit unit) {
- super(requestId, message);
-
- this.backoffMillis = unit.toMillis(backoff);
- }
-
- /**
- * Returns the number of milliseconds the client should backoff before retrying the request.
- *
- * @return backoff time, in seconds, before retrying the request, or {@code 0} if the request
- * can be retried immediately.
- */
- public long getBackoffMillis() {
- return backoffMillis;
- }
-}
-
diff --git a/src/autosaveworld/zlibs/com/dropbox/core/ServerException.java b/src/autosaveworld/zlibs/com/dropbox/core/ServerException.java
deleted file mode 100644
index d888a7db..00000000
--- a/src/autosaveworld/zlibs/com/dropbox/core/ServerException.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package autosaveworld.zlibs.com.dropbox.core;
-
-/**
- * The server said that something went wrong on its end (HTTP 500 error code).
- * This indicates bug on the Dropbox server, but there are multiple potential causes.
- *
- *
- *
Sometimes it's just a bug and there's nothing you can
- * do about it until its fixed. Report it on the Dropbox API forums.
- *
- *
Sometimes you're actually making an invalid request, but for some reason
- * the server's validation logic isn't catching the problem and it's
- * causing the server to error-out somewhere down the line. You may be able to
- * fix your request and get things working. This is still a bug on Dropbox's end,
- * so you should still report it on the Dropbox API forums.
- *
Sometimes the error is intermittent. It may only happen once every few
- * requests, in which case you can temporarily work around the issue by
- * retrying the request. Again, this still counts as a bug so report it on
- * the forums.
- *
Sometimes the error is temporary. For example, Dropbox might be experiencing
- * a temporary network or hardware issue. If you wait a few minutes, the error
- * might stop happening. You might want to check the forums to see if other
- * people are seeing the same thing.
- *
- */
-public class ServerException extends DbxException {
- private static final long serialVersionUID = 0;
-
- public ServerException(String requestId, String message) {
- super(requestId, message);
- }
-}
-
diff --git a/src/autosaveworld/zlibs/com/dropbox/core/http/HttpRequestor.java b/src/autosaveworld/zlibs/com/dropbox/core/http/HttpRequestor.java
deleted file mode 100644
index f98735b1..00000000
--- a/src/autosaveworld/zlibs/com/dropbox/core/http/HttpRequestor.java
+++ /dev/null
@@ -1,158 +0,0 @@
-package autosaveworld.zlibs.com.dropbox.core.http;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-import java.util.concurrent.TimeUnit;
-
-import autosaveworld.zlibs.com.dropbox.core.util.IOUtil;
-
-/**
- * An interface that the Dropbox client library uses to make HTTP requests.
- * If you're fine with the standard Java {@link java.net.HttpURLConnection}
- * implementation, then just use {@link StandardHttpRequestor#INSTANCE}.
- */
-public abstract class HttpRequestor
-{
- /**
- * Default timeout, in milliseconds, for opening a connection to a network resource.
- *
- * A value of 0 indicates the timeout should be disabled.
- */
- public static final long DEFAULT_CONNECT_TIMEOUT_MILLIS = TimeUnit.SECONDS.toMillis(20);
- /**
- * Default timeout, in milliseconds, for receiving a response from a network resource.
- *
- * A value of 0 indicates the timeout should be disabled.
- */
- // Careful about lowering this value. Large file uploads can result in slow responses from the
- // server.
- public static final long DEFAULT_READ_TIMEOUT_MILLIS = TimeUnit.MINUTES.toMillis(2);
-
- public abstract Response doGet(String url, Iterable headers) throws IOException;
- public abstract Uploader startPost(String url, Iterable headers) throws IOException;
- public abstract Uploader startPut(String url, Iterable headers) throws IOException;
-
- /**
- * A simple structure holding an HTTP header, which is key/value pair.
- * Used with {@link HttpRequestor}.
- */
- public static final class Header {
- private final String key;
- private final String value;
-
- public Header(String key, String value) {
- this.key = key;
- this.value = value;
- }
-
- /**
- * Returns header name.
- *
- * @return header name
- */
- public String getKey() {
- return key;
- }
-
- /**
- * Returns header value.
- *
- * @return header value
- */
- public String getValue() {
- return value;
- }
- }
-
- public static abstract class Uploader {
- public abstract OutputStream getBody();
- public abstract void close();
- public abstract void abort();
- public abstract Response finish() throws IOException;
-
- public void upload(InputStream in, long limit) throws IOException {
- upload(IOUtil.limit(in, limit));
- }
-
- public void upload(InputStream in) throws IOException {
- OutputStream out = getBody();
- try {
- IOUtil.copyStreamToStream(in, out);
- } catch (IOUtil.ReadException ex) {
- throw ex.getCause();
- } finally {
- out.close();
- }
- }
-
- public void upload(byte [] body) throws IOException {
- OutputStream out = getBody();
- try {
- out.write(body);
- } finally {
- out.close();
- }
- }
- }
-
- public static final class Response {
- private final int statusCode;
- private final InputStream body;
- private final Map> headers;
-
- public Response(int statusCode, InputStream body, Map> headers) {
- this.statusCode = statusCode;
- this.body = body;
- this.headers = asUnmodifiableCaseInsensitiveMap(headers);
- }
-
- /**
- * Returns HTTP status response code.
- *
- * @return HTTP status code
- */
- public int getStatusCode() {
- return statusCode;
- }
-
- /**
- * Returns an {@link InputStream} for reading the HTTP response body.
- *
- *
The returned stream must be fully read before closing.
- *
- * @return HTTP response body
- */
- public InputStream getBody() {
- return body;
- }
-
- /**
- * Returns a case-insensitive, unmodifiable mapping of header fields to their values.
- *
- * @return case-insensitive, unmodifiable headers
- */
- public Map> getHeaders() {
- return headers;
- }
-
- private static final Map> asUnmodifiableCaseInsensitiveMap(Map> original) {
- Map> insensitive = new TreeMap>(String.CASE_INSENSITIVE_ORDER);
- for (Map.Entry> entry : original.entrySet()) {
- // Java HttpURLConnection puts status line as the 'null' key, e.g.:
- //
- // HTTP/1.1 409 bad_member/invalid_dropbox_id/...
- //
- if (entry.getKey() == null || entry.getKey().trim().length() == 0) {
- continue;
- }
- insensitive.put(entry.getKey(), Collections.unmodifiableList(entry.getValue()));
- }
- return Collections.unmodifiableMap(insensitive);
- }
- }
-}
diff --git a/src/autosaveworld/zlibs/com/dropbox/core/http/StandardHttpRequestor.java b/src/autosaveworld/zlibs/com/dropbox/core/http/StandardHttpRequestor.java
deleted file mode 100644
index 8b05581a..00000000
--- a/src/autosaveworld/zlibs/com/dropbox/core/http/StandardHttpRequestor.java
+++ /dev/null
@@ -1,430 +0,0 @@
-package autosaveworld.zlibs.com.dropbox.core.http;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.HttpURLConnection;
-import java.net.Proxy;
-import java.net.URL;
-import java.util.concurrent.TimeUnit;
-
-import javax.net.ssl.HttpsURLConnection;
-
-import autosaveworld.zlibs.com.dropbox.core.util.IOUtil;
-
-/*>>> import checkers.nullness.quals.Nullable; */
-
-/**
- * {@link HttpRequestor} implementation that uses Java's standard library
- * {@link HttpsURLConnection}. If you just want a connection with the
- * default settings, use the predefined {@link #INSTANCE}.
- *
- *
- * If you want to customize the way the connection is configured, create a
- * subclass that overrides {@link #configureConnection}.
- *
- */
-public class StandardHttpRequestor extends HttpRequestor {
- /**
- * A thread-safe instance of {@code StandardHttpRequestor} that connects directly
- * (as opposed to using a proxy).
- */
- public static final StandardHttpRequestor INSTANCE = new StandardHttpRequestor(Config.DEFAULT_INSTANCE);
-
- private final Config config;
-
- /**
- * Creates an instance that connects through the given proxy.
- */
- public StandardHttpRequestor(Config config) {
- this.config = config;
- }
-
- private Response toResponse(HttpURLConnection conn) throws IOException {
- int responseCode = conn.getResponseCode();
- InputStream bodyStream;
- if (responseCode >= 400 || responseCode == -1) {
- bodyStream = conn.getErrorStream();
- } else {
- bodyStream = conn.getInputStream();
- }
- interceptResponse(conn);
- return new Response(responseCode, bodyStream, conn.getHeaderFields());
- }
-
- @Override
- public Response doGet(String url, Iterable headers) throws IOException {
- HttpURLConnection conn = prepRequest(url, headers);
- conn.setRequestMethod("GET");
- conn.connect();
- return toResponse(conn);
- }
-
- @Override
- public Uploader startPost(String url, Iterable headers) throws IOException {
- HttpURLConnection conn = prepRequest(url, headers);
- conn.setRequestMethod("POST");
- return new Uploader(conn);
- }
-
- @Override
- public Uploader startPut(String url, Iterable headers) throws IOException {
- HttpURLConnection conn = prepRequest(url, headers);
- conn.setRequestMethod("PUT");
- return new Uploader(conn);
- }
-
- /**
- * Can be overridden to configure the underlying {@link HttpsURLConnection} used to make
- * network requests. If you override this method, you should probably call
- * {@code super.configureConnection(conn)} in your overridden method.
- *
- * @deprecated use {@link #configure} instead.
- */
- @Deprecated
- protected void configureConnection(HttpsURLConnection conn) throws IOException { }
-
- /**
- * Can be overriden to configure the underlying {@link HttpURLConnection} used to make network
- * requests using https. Typically the connection will be a {@link
- * javax.net.ssl.HttpsURLConnection}, but that is dependent on the Java runtime. Care should be
- * taken when casting the connection (check your JRE).
- *
- *
If you are using Google App Engine, configure your {@link
- * autosaveworld.zlibs.com.dropbox.core.DbxRequestConfig} to use {@link GoogleAppEngineRequestor} as its default
- * {@code HttpRequestor}. If you use {@link StandardHttpRequestor} in Google App Engine, SSL
- * certificates may not be validated and your app will susceptible to Man-in-the-Middle attacks.
- *
- * @param conn URL connection object returned after creating an https network request.
- */
- protected void configure(HttpURLConnection conn) throws IOException { }
-
- /**
- * Called before returning {@link Response} from a request.
- *
- *
This method should be used by subclasses to add any logging, analytics, or cleanup
- * necessary. Note that the connection response code and response streams will already be
- * fetched before calling this method. This means any {@link IOException} from reading the
- * response should already have occurred before this method is called.
- *
- *
Do not consume the response or error streams in this method.
- *
- * @param conn HTTP URL connection
- */
- protected void interceptResponse(HttpURLConnection conn) throws IOException { }
-
- private static OutputStream getOutputStream(HttpURLConnection conn) throws IOException {
- conn.setDoOutput(true);
- return conn.getOutputStream();
- }
-
- private class Uploader extends HttpRequestor.Uploader {
- private final OutputStream out;
-
- private HttpURLConnection conn;
-
- public Uploader(HttpURLConnection conn) throws IOException {
- this.conn = conn;
- this.out = getOutputStream(conn);
-
- conn.connect();
- }
-
- @Override
- public OutputStream getBody() {
- return out;
- }
-
- @Override
- public void abort() {
- if (conn == null) {
- throw new IllegalStateException("Can't abort(). Uploader already closed.");
- }
- // disconnecting is "harsh" in that it can close the underlying streams and socket. This
- // prevents connection re-use.
- conn.disconnect();
- conn = null;
- }
-
- @Override
- public void close() {
- if (conn == null) return;
-
- // close input and output streams to allow for connection re-use.
- if (conn.getDoOutput()) {
- try {
- IOUtil.closeQuietly(conn.getOutputStream());
- } catch (IOException ex) {
- // ignore
- }
- }
-
- // should not need to disconnect after closing the relevant streams
- conn = null;
- }
-
- @Override
- public Response finish() throws IOException {
- if (conn == null) {
- throw new IllegalStateException("Can't finish(). Uploader already closed.");
- }
-
- try {
- return toResponse(conn);
- } finally {
- conn = null;
- }
- }
- }
-
- private HttpURLConnection prepRequest(String url, Iterable headers) throws IOException {
- URL urlObject = new URL(url);
- HttpURLConnection conn = (HttpURLConnection) urlObject.openConnection(config.getProxy());
-
- conn.setConnectTimeout((int) config.getConnectTimeoutMillis());
- conn.setReadTimeout((int) config.getReadTimeoutMillis());
- conn.setUseCaches(false);
- conn.setAllowUserInteraction(false);
-
- // Some JREs (like the one provided by Google AppEngine) will return HttpURLConnection
- // instead of HttpsURLConnection. So we have to check here.
- // AutoSaveWorld - do not do pinning for now
-// if (conn instanceof HttpsURLConnection) {
-// SSLConfig.apply((HttpsURLConnection) conn);
-// configureConnection((HttpsURLConnection) conn);
-// } else {
-// logCertificatePinningWarning();
-// }
-
- configure(conn);
-
- for (Header header : headers) {
- conn.addRequestProperty(header.getKey(), header.getValue());
- }
-
- return conn;
- }
-
-// private static void logCertificatePinningWarning() {
-// if (!certPinningWarningLogged) {
-// certPinningWarningLogged = true;
-// LOGGER.warning("Certificate pinning disabled for HTTPS connections. This is likely because your JRE does not " +
-// "return javax.net.ssl.HttpsURLConnection objects for https network connections. Be aware your app " +
-// "may be prone to man-in-the-middle attacks without proper SSL certificate validation. If you are " +
-// "using Google App Engine, please configure DbxRequestConfig to use GoogleAppEngineRequestor.");
-// }
-// }
-
- /**
- * Configuration for {@link StandardHttpRequestor} that determines
- * how network connections to the server are established.
- *
- * Use this class to configure timeouts and proxy settings.
- *
- * Some requests may require different connection settings than
- * others. Create multiple {@link StandardHttpRequestor} objects
- * with different configurations to handle these requests. For
- * example, calls to {@link
- * autosaveworld.zlibs.com.dropbox.core.v2.files.DbxUserFilesRequests#listFolderLongpoll(String,long)} should
- * use a {@code StandardHttpRequestor} with its read timeout (see
- * {@link Builder#withReadTimeout}) set longer than the longpoll
- * timeout.
- */
- public static final class Config {
- /**
- * {@link Config} with all its attributes set to their default
- * values.
- */
- public static final Config DEFAULT_INSTANCE = builder().build();
-
- private final Proxy proxy;
- private final long connectTimeoutMillis;
- private final long readTimeoutMillis;
-
- private Config(Proxy proxy,
- long connectTimeoutMillis,
- long readTimeoutMillis) {
- this.proxy = proxy;
- this.connectTimeoutMillis = connectTimeoutMillis;
- this.readTimeoutMillis = readTimeoutMillis;
- }
-
- /**
- * Returns the proxy configuration for network connections.
- *
- * @return proxy configuration to use for network connections.
- */
- public Proxy getProxy() {
- return proxy;
- }
-
- /**
- * Returns the timeout, in milliseconds, for opening a
- * connection to the servers.
- *
- * If the timeout is 0, then connect timeouts are disabled.
- *
- * @return timeout, in milliseconds, for opening connections
- * to the servers.
- */
- public long getConnectTimeoutMillis() {
- return connectTimeoutMillis;
- }
-
- /**
- * Returns the timeout, in milliseconds, for receiving a
- * response from the servers.
- *
- * If the timeout is 0, then read timeouts are disabled.
- *
- * @return timeout, in milliseconds, for receiving a response
- * from the server.
- */
- public long getReadTimeoutMillis() {
- return readTimeoutMillis;
- }
-
- /**
- * Returns a new builder for creating a copy of this
- * config. The builder is configured to use this config's
- * values as its default.
- *
- * @return builder for creating a copy of this config.
- */
- public Builder copy() {
- return new Builder(proxy, connectTimeoutMillis, readTimeoutMillis);
- }
-
- /**
- * Returns a new builder for creating a {@link Config}.
- *
- * @return builder for creating an instance of this class
- */
- public static Builder builder() {
- return new Builder();
- }
-
- /**
- * Builder for {@link Config}.
- */
- public static final class Builder {
- private Proxy proxy;
- private long connectTimeoutMillis;
- private long readTimeoutMillis;
-
- private Builder() {
- this(Proxy.NO_PROXY, DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS);
- }
-
- private Builder(Proxy proxy, long connectTimeoutMillis, long readTimeoutMillis) {
- this.proxy = proxy;
- this.connectTimeoutMillis = connectTimeoutMillis;
- this.readTimeoutMillis = readTimeoutMillis;
- }
-
- /**
- * Set proxy configuration for network connections.
- *
- * @param proxy Proxy configuration
- *
- * @return this builder
- *
- * @throws NullPointerException if {@code proxy} is {@code null}
- */
- public Builder withProxy(Proxy proxy) {
- if (proxy == null) {
- throw new NullPointerException("proxy");
- }
- this.proxy = proxy;
- return this;
- }
-
- /**
- * Disables timeouts for opening a connection to the
- * servers.
- *
- * @return this builder
- */
- public Builder withNoConnectTimeout() {
- return withConnectTimeout(0L, TimeUnit.MILLISECONDS);
- }
-
- /**
- * Set timeout for opening a connection to the servers.
- *
- * A timeout of 0 will disable any connnect timeouts.
- *
- * @param timeout time to wait for a network connection to open
- * @param unit unit of time
- *
- * @return this builder
- *
- * @throws IllegalArgumentException if {@code timeout} is negative
- * @throws NullPointerException if {@code unit} is {@code null}
- */
- public Builder withConnectTimeout(long timeout, TimeUnit unit) {
- this.connectTimeoutMillis = checkTimeoutMillis(timeout, unit);
- return this;
- }
-
- /**
- * Disables timeout for receiving a response from the servers.
- *
- * @return this builder
- */
- public Builder withNoReadTimeout() {
- return withReadTimeout(0L, TimeUnit.MILLISECONDS);
- }
-
- /**
- * Sets timeout for receiving a response from the servers.
- *
- * This timeout is not for receiving the entire server
- * response. A server that responds with bytes slowly will
- * not trigger the timeout, unless the specified amount of
- * time has passed between received bytes.
- *
- * A timeout of 0 will disable any read timeouts.
- *
- * @param timeout time to wait for a response from the server
- * @param unit unit of time
- *
- * @return this builder
- *
- * @throws IllegalArgumentException if {@code timeout} is negative
- * @throws NullPointerException if {@code unit} is {@code null}
- */
- public Builder withReadTimeout(long timeout, TimeUnit unit) {
- this.readTimeoutMillis = checkTimeoutMillis(timeout, unit);
- return this;
- }
-
- /**
- * Returns a {@link Config} with the values set by this builder.
- *
- * @return {@link Config} with this builder's values
- */
- public Config build() {
- return new Config(
- proxy,
- connectTimeoutMillis,
- readTimeoutMillis
- );
- }
-
- private static long checkTimeoutMillis(long timeout, TimeUnit unit) {
- if (unit == null) {
- throw new NullPointerException("unit");
- }
- if (timeout < 0) {
- throw new IllegalArgumentException("timeout must be non-negative");
- }
- long millis = unit.toMillis(timeout);
- if (Integer.MAX_VALUE < millis) {
- throw new IllegalArgumentException("timeout too large, must be less than: " + Integer.MAX_VALUE);
- }
- return millis;
- }
- }
- }
-}
diff --git a/src/autosaveworld/zlibs/com/dropbox/core/json/JsonArrayReader.java b/src/autosaveworld/zlibs/com/dropbox/core/json/JsonArrayReader.java
deleted file mode 100644
index 7a67f6fa..00000000
--- a/src/autosaveworld/zlibs/com/dropbox/core/json/JsonArrayReader.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package autosaveworld.zlibs.com.dropbox.core.json;
-
-import java.io.IOException;
-import java.util.List;
-
-import autosaveworld.zlibs.com.dropbox.core.util.Collector;
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonParser;
-
-public class JsonArrayReader extends JsonReader
-{
- public final JsonReader extends T> elementReader;
- public final Collector collector;
-
- public JsonArrayReader(JsonReader extends T> elementReader, Collector collector)
- {
- this.elementReader = elementReader;
- this.collector = collector;
- }
-
- public static JsonArrayReader> mk(JsonReader extends T> elementReader)
- {
- return new JsonArrayReader>(elementReader, new Collector.ArrayListCollector());
- }
-
- public static JsonArrayReader mk(JsonReader extends T> elementReader, Collector collector)
- {
- return new JsonArrayReader(elementReader, collector);
- }
-
- public L read(JsonParser parser)
- throws JsonReadException, IOException
- {
- return read(elementReader, collector, parser);
- }
-
- public static L read(JsonReader extends T> elementReader, Collector collector, JsonParser parser)
- throws JsonReadException, IOException
- {
- expectArrayStart(parser);
-
- int index = 0;
- while (!isArrayEnd(parser)) {
- try {
- T value = elementReader.read(parser);
- collector.add(value);
- index++;
- }
- catch (JsonReadException ex) {
- throw ex.addArrayContext(index);
- }
- }
-
- parser.nextToken();
- return collector.finish();
- }
-}
diff --git a/src/autosaveworld/zlibs/com/dropbox/core/json/JsonDateReader.java b/src/autosaveworld/zlibs/com/dropbox/core/json/JsonDateReader.java
deleted file mode 100644
index 165486f8..00000000
--- a/src/autosaveworld/zlibs/com/dropbox/core/json/JsonDateReader.java
+++ /dev/null
@@ -1,292 +0,0 @@
-package autosaveworld.zlibs.com.dropbox.core.json;
-
-import java.io.IOException;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.TimeZone;
-
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonLocation;
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonParseException;
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonParser;
-
-public class JsonDateReader
-{
- /**
- * A parser for dates returned by the Dropbox API.
- */
- public static final JsonReader Dropbox = new JsonReader() {
- @Override
- public Date read(JsonParser parser) throws IOException, JsonReadException
- {
- JsonLocation l = parser.getCurrentLocation();
- try {
- char[] buffer = parser.getTextCharacters();
- int offset = parser.getTextOffset();
- int length = parser.getTextLength();
- Date d = parseDropboxDate(buffer, offset, length);
- parser.nextToken();
- return d;
- }
- catch (JsonParseException ex) {
- throw JsonReadException.fromJackson(ex);
- }
- catch (java.text.ParseException ex) {
- throw new JsonReadException("bad date: \"" + ex.getMessage() + " at offset " + ex.getErrorOffset(), l);
- }
- }
- };
-
- public static Date parseDropboxDate(char[] buffer, int offset, int length)
- throws java.text.ParseException
- {
- int i = offset;
- char[] b = buffer;
-
- if (length != 31) {
- throw new java.text.ParseException("expecting date to be 31 characters, got " + length, 0);
- }
-
- // Hopefully this check lets the JVM eliminate array bounds checks for the rest of the function.
- if (b.length < i + 31 || i < 0) {
- throw new IllegalArgumentException("range is not within 'b'");
- }
-
- // 0 1 2 3
- // 0123456789012345678901234567890
- // DDD, DD MMM YYYY HH:MM:SS +0000
-
- // Check for fixed values. Using non-short-circuit OR because it's faster
- // for the common case of them all being correct.
- if (b[i+3] != ',' | b[i+4] != ' ' | b[i+7] != ' ' | b[i+11] != ' '
- | b[i+16] != ' ' | b[i+19] != ':' | b[i+22] != ':' | b[i+25] != ' '
- | b[i+26] != '+' | b[i+27] != '0' | b[i+28] != '0' | b[i+29] != '0' | b[i+30] != '0') {
- if (b[i+3] != ',') throw new java.text.ParseException("expecting ','", 3);
- if (b[i+4] != ' ') throw new java.text.ParseException("expecting ' '", 4);
- if (b[i+7] != ' ') throw new java.text.ParseException("expecting ' '", 7);
- if (b[i+11] != ' ') throw new java.text.ParseException("expecting ' '", 11);
- if (b[i+16] != ' ') throw new java.text.ParseException("expecting ' '", 16);
- if (b[i+19] != ':') throw new java.text.ParseException("expecting ':'", 19);
- if (b[i+22] != ':') throw new java.text.ParseException("expecting ':'", 22);
- if (b[i+25] != ' ') throw new java.text.ParseException("expecting ' '", 25);
- if (b[i+26] != '+') throw new java.text.ParseException("expecting '+'", 26);
- if (b[i+27] != '0') throw new java.text.ParseException("expecting '0'", 27);
- if (b[i+28] != '0') throw new java.text.ParseException("expecting '0'", 28);
- if (b[i+29] != '0') throw new java.text.ParseException("expecting '0'", 29);
- if (b[i+30] != '0') throw new java.text.ParseException("expecting '0'", 30);
- throw new AssertionError("unreachable");
- }
-
- // Parse day of week string.
- if (!isValidDayOfWeek(b[i], b[i+1], b[i+2])) {
- throw new java.text.ParseException("invalid day of week", i);
- }
-
- // Month string.
- int month = getMonthIndex(b[i+8], b[i+9], b[i+10]);
- if (month == -1) {
- throw new java.text.ParseException("invalid month", 8);
- }
-
- // Day of month.
- char d1 = b[i+5];
- char d2 = b[i+6];
-
- if (!isDigit(d1) || !isDigit(d2)) {
- throw new java.text.ParseException("invalid day of month", 5);
- }
-
- int dayOfMonth = d1*10 + d2 - ('0' * 11);
-
- // Year
- char y1 = b[i+12];
- char y2 = b[i+13];
- char y3 = b[i+14];
- char y4 = b[i+15];
-
- if (!isDigit(y1) | !isDigit(y2) | !isDigit(y3) | !isDigit(y4)) {
- throw new java.text.ParseException("invalid year", 12);
- }
-
- int year = y1*1000 + y2*100 + y3*10 + y4 - ('0' * 1111);
-
- // Hour
- char h1 = b[i+17];
- char h2 = b[i+18];
-
- if (!isDigit(h1) | !isDigit(h2)) {
- throw new java.text.ParseException("invalid hour", 17);
- }
-
- int hour = h1*10 + h2 - ('0' * 11);
-
- // Minute
- char m1 = b[i+20];
- char m2 = b[i+21];
-
- if (!isDigit(m1) | !isDigit(m2)) {
- throw new java.text.ParseException("invalid minute", 20);
- }
-
- int minute = m1*10 + m2 - ('0' * 11);
-
- // Second
- char s1 = b[i+23];
- char s2 = b[i+24];
-
- if (!isDigit(s1) | !isDigit(s2)) {
- throw new java.text.ParseException("invalid second", 23);
- }
-
- int second = s1*10 + s2 - ('0' * 11);
-
- // TODO: How do we validate that the numbers are in range?
- GregorianCalendar c = new GregorianCalendar(year, month, dayOfMonth, hour, minute, second);
- c.setTimeZone(UTC);
- return c.getTime();
- }
-
- public static final TimeZone UTC = TimeZone.getTimeZone("UTC");
-
- private static boolean isDigit(char c)
- {
- return c >= '0' && c <= '9';
- }
-
- public static boolean isValidDayOfWeek(char a, char b, char c)
- {
- // Using non-short-circuit AND because it's faster for the common case of the values being correct.
- switch (a) {
- case 'S':
- if (b == 'u' & c == 'n') return true;
- if (b == 'a' & c == 't') return true;
- return false;
- case 'M':
- if (b == 'o' & c == 'n') return true;
- return false;
- case 'T':
- if (b == 'u' & c == 'e') return true;
- if (b == 'h' & c == 'u') return true;
- return false;
- case 'W':
- if (b == 'e' & c == 'd') return true;
- return false;
- case 'F':
- if (b == 'r' & c == 'i') return true;
- return false;
- default:
- return false;
- }
- }
-
- public static int getMonthIndex(char a, char b, char c)
- {
- switch (a) {
- case 'J':
- if (b == 'a' & c == 'n') return 0;
- if (b == 'u') {
- if (c == 'n') return 5;
- if (c == 'l') return 6;
- return -1;
- }
- return -1;
- case 'F':
- if (b == 'e' & c == 'b') return 1;
- return 0;
- case 'M':
- if (b == 'a') {
- if (c == 'r') return 2;
- if (c == 'y') return 4;
- return -1;
- }
- return -1;
- case 'A':
- if (b == 'p' & c == 'r') return 3;
- if (b == 'u' & c == 'g') return 7;
- return -1;
- case 'S':
- if (b == 'e' & c == 'p') return 8;
- return -1;
- case 'O':
- if (b == 'c' & c == 't') return 9;
- return -1;
- case 'N':
- if (b == 'o' & c == 'v') return 10;
- return -1;
- case 'D':
- if (b == 'e' & c == 'c') return 11;
- return -1;
- default:
- return -1;
- }
- }
-
- /**
- * A parser for dates returned by the Dropbox V2 API.
- *
- * This parses only the new ISO 8601 format
- * (e.g. {@literal "2010-01-01T12:00:00Z"}
- * or {@literal "2010-01-01T12:00:00.000Z"}).
- */
- public static final JsonReader DropboxV2 = new JsonReader() {
- @Override
- public Date read(JsonParser parser) throws IOException, JsonReadException
- {
- JsonLocation l = parser.getCurrentLocation();
- try {
- char[] buffer = parser.getTextCharacters();
- int offset = parser.getTextOffset();
- int length = parser.getTextLength();
- Date d = parseDropbox8601Date(buffer, offset, length);
- parser.nextToken();
- return d;
- }
- catch (JsonParseException ex) {
- throw JsonReadException.fromJackson(ex);
- }
- catch (java.text.ParseException ex) {
- throw new JsonReadException("bad date: \"" + ex.getMessage() + " at offset " + ex.getErrorOffset(), l);
- }
- }
- };
-
- public static Date parseDropbox8601Date(char[] buffer, int offset, int length)
- throws java.text.ParseException
- {
- int i = offset;
- char[] b = buffer;
-
- if (length != 20 && length != 24) {
- throw new java.text.ParseException("expecting date to be 20 or 24 characters, got " + length, 0);
- }
-
- // TODO: This needs to be looked at further.
- // Does this need to handle arbitrary timezones?
- String s = new String(b, i, length);
- final DateFormat format;
- if (length == 20) {
- // Assume this is an ISO 8601 date with a trailing Z to indicate UTC:
- // e.g. "2015-04-01T12:01:12Z",
- format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
- } else {
- // Assume this is an ISO 8601 date with a trailing Z to indicate UTC:
- // plus milliseconds, e.g. "2012-04-23T18:25:43.511Z".
- format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
- }
- format.setTimeZone(TimeZone.getTimeZone("UTC"));
-
- Date result;
- try {
- result = format.parse(s);
- } catch (IllegalArgumentException ex) {
- throw new java.text.ParseException("invalid characters in date" + s, 0);
- }
-
- if (result == null) {
- throw new java.text.ParseException("invalid date" + s, 0);
- }
-
- return result;
- }
-}
diff --git a/src/autosaveworld/zlibs/com/dropbox/core/json/JsonReadException.java b/src/autosaveworld/zlibs/com/dropbox/core/json/JsonReadException.java
deleted file mode 100644
index e9586e69..00000000
--- a/src/autosaveworld/zlibs/com/dropbox/core/json/JsonReadException.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package autosaveworld.zlibs.com.dropbox.core.json;
-
-import java.io.File;
-
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonLocation;
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonProcessingException;
-
-/*>>> import checkers.nullness.quals.Nullable; */
-
-public final class JsonReadException extends java.lang.Exception
-{
- public static final long serialVersionUID = 0;
-
- public final String error;
- public final JsonLocation location;
- private /*@Nullable*/PathPart path;
-
- public JsonReadException(String error, JsonLocation location)
- {
- this.error = error;
- this.location = location;
- this.path = null;
- }
-
- public JsonReadException(String error, JsonLocation location, Throwable cause)
- {
- super(cause);
- this.error = error;
- this.location = location;
- this.path = null;
- }
-
- public JsonReadException addFieldContext(String fieldName)
- {
- this.path = new PathPart('"' + fieldName + '"', this.path);
- return this;
- }
-
- public JsonReadException addArrayContext(int index)
- {
- this.path = new PathPart(Integer.toString(index), this.path);
- return this;
- }
-
- public String getMessage()
- {
- StringBuilder buf = new StringBuilder();
-
- // Location
- toStringLocation(buf, location);
- buf.append(": ");
-
- // "Logical Path"
- if (path != null) {
- PathPart p = path;
- buf.append(p.description);
- while (p.next != null) {
- p = p.next;
- buf.append(".");
- buf.append(p.description);
- }
- buf.append(": ");
- }
-
- // Actual error message.
- buf.append(error);
-
- return buf.toString();
- }
-
- public static void toStringLocation(StringBuilder buf, JsonLocation location)
- {
- Object sourceRef = location.getSourceRef();
- if (sourceRef instanceof File) {
- File f = (File) sourceRef;
- buf.append(f.getPath());
- buf.append(": ");
- }
-
- buf.append(location.getLineNr());
- buf.append(".");
- buf.append(location.getColumnNr());
- }
-
- public static final class PathPart
- {
- public final String description;
- public final /*@Nullable*/PathPart next;
-
- public PathPart(String description, /*@Nullable*/PathPart next)
- {
- this.description = description;
- this.next = next;
- }
- }
-
- public static JsonReadException fromJackson(JsonProcessingException ex)
- {
- String message = ex.getMessage();
-
- // Strip off location.
- int locPos = message.lastIndexOf(" at [Source");
- if (locPos >= 0) {
- message = message.substring(0, locPos);
- }
-
- return new JsonReadException(message, ex.getLocation());
- }
-}
diff --git a/src/autosaveworld/zlibs/com/dropbox/core/json/JsonReader.java b/src/autosaveworld/zlibs/com/dropbox/core/json/JsonReader.java
deleted file mode 100644
index c105cb7a..00000000
--- a/src/autosaveworld/zlibs/com/dropbox/core/json/JsonReader.java
+++ /dev/null
@@ -1,574 +0,0 @@
-package autosaveworld.zlibs.com.dropbox.core.json;
-
-import static autosaveworld.zlibs.com.dropbox.core.util.LangUtil.mkAssert;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.HashMap;
-
-import autosaveworld.zlibs.com.dropbox.core.util.IOUtil;
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonFactory;
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonLocation;
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonParseException;
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonParser;
-import autosaveworld.zlibs.com.fasterxml.jackson.core.JsonToken;
-
-/*>>> import checkers.nullness.quals.Nullable; */
-
-public abstract class JsonReader
-{
- public abstract T read(JsonParser parser)
- throws IOException, JsonReadException;
-
- public T readFromTags(String[] tags, JsonParser parser)
- throws IOException, JsonReadException
- {
- return null; // Must override for struct
- }
-
- public T readFields(JsonParser parser)
- throws IOException, JsonReadException
- {
- return null; // Must override for struct
- }
-
- public void validate(T value)
- {
- // Base implementation does nothing.
- }
-
- public final T readField(JsonParser parser, String fieldName, /*@Nullable*/T v)
- throws IOException, JsonReadException
- {
- if (v != null) throw new JsonReadException("duplicate field \"" + fieldName + "\"", parser.getTokenLocation());
- return read(parser);
- }
-
- public final /*@Nullable*/T readOptional(JsonParser parser)
- throws IOException, JsonReadException
- {
- if (parser.getCurrentToken() == JsonToken.VALUE_NULL) {
- parser.nextToken();
- return null;
- } else {
- return read(parser);
- }
- }
-
- /**
- * Helper to read and parse the optional ".tag" field. If one is found, positions the parser
- * at the next field (or the closing brace); otherwise leaves the parser position unchanged.
- * Returns null if there isn't a ".tag" field; otherwise an array of strings (the tags).
- * Initially the parser must be positioned right after the opening brace.
- */
- public static String[] readTags(JsonParser parser)
- throws IOException, JsonReadException
- {
- if (parser.getCurrentToken() != JsonToken.FIELD_NAME) {
- return null;
- }
- if (!".tag".equals(parser.getCurrentName())) {
- return null;
- }
- parser.nextToken();
- if (parser.getCurrentToken() != JsonToken.VALUE_STRING) {
- throw new JsonReadException("expected a string value for .tag field", parser.getTokenLocation());
- }
- String tag = parser.getText();
- parser.nextToken();
- return tag.split("\\.");
- }
-
- /**
- * A wrapper around 'JsonParser.nextToken' that throws our own better {@link JsonReadException}
- * instead of Jackson's {@link JsonParseException}.
- *
- * JsonParseException is bad for two reasons. First, it extends IOException, which makes it easy to
- * miss. Second, there's no way to get the original error message, which makes it hard to chain
- * logical location information (see {@link JsonReadException#addFieldContext} and
- * {@link JsonReadException#addArrayContext}).
- */
- public static JsonToken nextToken(JsonParser parser)
- throws IOException, JsonReadException
- {
- try {
- return parser.nextToken();
- }
- catch (JsonParseException ex) {
- throw JsonReadException.fromJackson(ex);
- }
- }
-
- // ------------------------------------------------------------------
- // Delimiter checking helpers.
-
- public static JsonLocation expectObjectStart(JsonParser parser)
- throws IOException, JsonReadException
- {
- if (parser.getCurrentToken() != JsonToken.START_OBJECT) {
- throw new JsonReadException("expecting the start of an object (\"{\")", parser.getTokenLocation());
- }
- JsonLocation loc = parser.getTokenLocation();
- nextToken(parser);
- return loc;
- }
-
- public static void expectObjectEnd(JsonParser parser)
- throws IOException, JsonReadException
- {
- if (parser.getCurrentToken() != JsonToken.END_OBJECT) {
- throw new JsonReadException("expecting the end of an object (\"}\")", parser.getTokenLocation());
- }
- nextToken(parser);
- }
-
- public static JsonLocation expectArrayStart(JsonParser parser)
- throws IOException, JsonReadException
- {
- if (parser.getCurrentToken() != JsonToken.START_ARRAY) {
- throw new JsonReadException("expecting the start of an array (\"[\")", parser.getTokenLocation());
- }
- JsonLocation loc = parser.getTokenLocation();
- nextToken(parser);
- return loc;
- }
-
- public static JsonLocation expectArrayEnd(JsonParser parser)
- throws IOException, JsonReadException
- {
- if (parser.getCurrentToken() != JsonToken.END_ARRAY) {
- throw new JsonReadException("expecting the end of an array (\"[\")", parser.getTokenLocation());
- }
- JsonLocation loc = parser.getTokenLocation();
- nextToken(parser);
- return loc;
- }
-
- public static boolean isArrayEnd(JsonParser parser)
- {
- return (parser.getCurrentToken() == JsonToken.END_ARRAY);
- }
-
- public static boolean isArrayStart(JsonParser parser)
- {
- return (parser.getCurrentToken() == JsonToken.START_ARRAY);
- }
-
- public static void skipValue(JsonParser parser)
- throws IOException, JsonReadException
- {
- try {
- parser.skipChildren();
- parser.nextToken();
- }
- catch (JsonParseException ex) {
- throw JsonReadException.fromJackson(ex);
- }
- }
-
- // ------------------------------------------------------------------
- // Helpers for various types.
-
- public static final JsonReader UnsignedLongReader = new JsonReader() {
- @Override
- public Long read(JsonParser parser)
- throws IOException, JsonReadException
- {
- return readUnsignedLong(parser);
- }
- };
-
- public static long readUnsignedLong(JsonParser parser)
- throws IOException, JsonReadException
- {
- try {
- long v = parser.getLongValue();
- if (v < 0) {
- throw new JsonReadException("expecting a non-negative number, got: " + v, parser.getTokenLocation());
- }
- parser.nextToken();
- return v;
- }
- catch (JsonParseException ex) {
- throw JsonReadException.fromJackson(ex);
- }
- }
-
- public static long readUnsignedLongField(JsonParser parser, String fieldName, long v)
- throws IOException, JsonReadException
- {
- if (v >= 0) throw new JsonReadException("duplicate field \"" + fieldName + "\"", parser.getCurrentLocation());
- return JsonReader.readUnsignedLong(parser);
- }
-
- public static final JsonReader Int64Reader = new JsonReader()
- {
- public Long read(JsonParser parser)
- throws IOException, JsonReadException
- {
- long v = parser.getLongValue();
- parser.nextToken();
- return v;
- }
- };
-
- public static final JsonReader Int32Reader = new JsonReader()
- {
- public Integer read(JsonParser parser)
- throws IOException, JsonReadException
- {
- int v = parser.getIntValue();
- parser.nextToken();
- return v;
- }
- };
-
- // NOTE: This can't read values >= 2**63.
- public static final JsonReader UInt64Reader = new JsonReader()
- {
- public Long read(JsonParser parser)
- throws IOException, JsonReadException
- {
- return readUnsignedLong(parser);
- }
- };
-
- // NOTE: This stores the value in a Long.
- public static final JsonReader UInt32Reader = new JsonReader()
- {
- public Long read(JsonParser parser)
- throws IOException, JsonReadException
- {
- long v = readUnsignedLong(parser);
- if (v >= 4294967296L) {
- throw new JsonReadException("expecting a 32-bit unsigned integer, got: " + v, parser.getTokenLocation());
- }
- return v;
- }
- };
-
- public static final JsonReader Float64Reader = new JsonReader()
- {
- public Double read(JsonParser parser)
- throws IOException, JsonReadException
- {
- double v = parser.getDoubleValue();
- parser.nextToken();
- return v;
- }
- };
-
- public static final JsonReader Float32Reader = new JsonReader()
- {
- public Float read(JsonParser parser)
- throws IOException, JsonReadException
- {
- float v = parser.getFloatValue();
- parser.nextToken();
- return v;
- }
- };
-
- public static final JsonReader StringReader = new JsonReader()
- {
- public String read(JsonParser parser)
- throws IOException, JsonReadException
- {
- try {
- String v = parser.getText();
- parser.nextToken();
- return v;
- }
- catch (JsonParseException ex) {
- throw JsonReadException.fromJackson(ex);
- }
- }
- };
-
- public static final JsonReader BinaryReader = new JsonReader()
- {
- public byte[] read(JsonParser parser)
- throws IOException, JsonReadException
- {
- try {
- // TODO: Jackson's base64 parser is more lenient than we want (it allows whitespace
- // and other junk in some places). Switch to something more strict.
- byte[] v = parser.getBinaryValue();
- parser.nextToken();
- return v;
- }
- catch (JsonParseException ex) {
- throw JsonReadException.fromJackson(ex);
- }
- }
- };
-
- public static final JsonReader BooleanReader = new JsonReader()
- {
- public Boolean read(JsonParser parser)
- throws IOException, JsonReadException
- {
- return readBoolean(parser);
- }
- };
-
- public static boolean readBoolean(JsonParser parser)
- throws IOException, JsonReadException
- {
- try {
- boolean b = parser.getBooleanValue();
- parser.nextToken();
- return b;
- }
- catch (JsonParseException ex) {
- throw JsonReadException.fromJackson(ex);
- }
- }
-
- public static double readDouble(JsonParser parser)
- throws IOException, JsonReadException
- {
- try {
- double v = parser.getDoubleValue();
- parser.nextToken();
- return v;
- } catch (JsonParseException ex) {
- throw JsonReadException.fromJackson(ex);
- }
- }
-
- public static final JsonReader