Skip to content

Commit f7586bc

Browse files
author
Kannan Goundan
committed
Add support for most API calls; lots of reorg.
- JsonExtractor -> JsonReader - Don't have "...AndClose" methods for InputStreams. Turns out it doesn't really help that much. - Rework DbxDataObject to do single-line and multi-line dumps.
1 parent 888d45c commit f7586bc

27 files changed

Lines changed: 2262 additions & 647 deletions

ChangeLog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
- Added support for most API calls.
2+
- Very minor backwards-incompatibility.
3+
14
---------------------------------------------
25
1.6 (2013-07-07)
36

examples/authorize/src/com/dropbox/core/examples/authorize/ConfigHelper.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ public static AppInfoAndHostJson loadAppInfoAndRawJson(String file)
3838
ByteArrayOutputStream out = new ByteArrayOutputStream();
3939

4040
try {
41-
IOUtil.copyStreamToStreamAndCloseInput(new FileInputStream(file), out);
41+
FileInputStream fin = new FileInputStream(file);
42+
try {
43+
IOUtil.copyStreamToStream(fin, out);
44+
}
45+
finally {
46+
IOUtil.closeInput(fin);
47+
}
4248
}
4349
catch (IOException ex) {
4450
throw new Exception("unable to read file \"" + file + "\": " + ex.getMessage());

pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@
8181
<encoding>UTF-8</encoding>
8282
</configuration>
8383
</plugin>
84+
<plugin>
85+
<groupId>org.apache.maven.plugins</groupId>
86+
<artifactId>maven-surefire-plugin</artifactId>
87+
<version>2.15</version>
88+
<configuration>
89+
<skipTests>${skipTests}</skipTests>
90+
</configuration>
91+
</plugin>
8492
</plugins>
8593
</build>
8694

@@ -120,5 +128,6 @@
120128

121129
<properties>
122130
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
131+
<skipTests>true</skipTests>
123132
</properties>
124133
</project>

src/com/dropbox/core/DbxAccountInfo.java

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
import com.dropbox.core.json.JsonReadException;
44
import com.dropbox.core.json.JsonReader;
55
import com.dropbox.core.util.DumpWriter;
6-
import static com.dropbox.core.util.StringUtil.jq;
6+
import com.dropbox.core.util.Dumpable;
7+
78
import com.fasterxml.jackson.core.JsonLocation;
89
import com.fasterxml.jackson.core.JsonParser;
910
import com.fasterxml.jackson.core.JsonToken;
1011

1112
import java.io.IOException;
1213

13-
public class DbxAccountInfo extends DbxDataObject
14+
public class DbxAccountInfo extends Dumpable
1415
{
1516
public final long userId;
1617
public final String displayName;
@@ -30,28 +31,14 @@ public DbxAccountInfo(long userId, String displayName, String country, String re
3031
@Override
3132
protected void dumpFields(DumpWriter out)
3233
{
33-
out.field("userId");
34-
dump(out, Long.toString(userId));
35-
36-
out.field("displayName");
37-
dump(out, displayName);
38-
39-
out.field("country");
40-
dump(out, country);
41-
42-
out.field("referralLink");
43-
dump(out, referralLink);
44-
45-
out.field("quota");
46-
dump(out, quota);
47-
}
48-
49-
public String toString()
50-
{
51-
return "(" + userId + ", " + jq(displayName) + ")";
34+
out.field("userId", userId);
35+
out.field("displayName", displayName);
36+
out.field("country", country);
37+
out.field("referralLink", referralLink);
38+
out.field("quota", quota);
5239
}
5340

54-
public static final class Quota extends DbxDataObject
41+
public static final class Quota extends Dumpable
5542
{
5643
public final long total;
5744
public final long normal;
@@ -67,14 +54,9 @@ public Quota(long quota, long normal, long quotaShared)
6754
@Override
6855
protected void dumpFields(DumpWriter out)
6956
{
70-
out.field("total");
71-
dump(out, Long.toString(total));
72-
73-
out.field("normal");
74-
dump(out, Long.toString(normal));
75-
76-
out.field("shared");
77-
dump(out, Long.toString(shared));
57+
out.field("total", total);
58+
out.field("normal", normal);
59+
out.field("shared", shared);
7860
}
7961

8062
// ------------------------------------------------------
@@ -102,9 +84,9 @@ public final Quota read(JsonParser parser)
10284
JsonReader.skipValue(parser);
10385
}
10486
switch (fi) {
105-
case FM_quota: quota = JsonReader.extractUnsignedLongField(parser, fieldName, quota); break;
106-
case FM_normal: normal = JsonReader.extractUnsignedLongField(parser, fieldName, normal); break;
107-
case FM_shared: shared = JsonReader.extractUnsignedLongField(parser, fieldName, shared); break;
87+
case FM_quota: quota = JsonReader.readUnsignedLongField(parser, fieldName, quota); break;
88+
case FM_normal: normal = JsonReader.readUnsignedLongField(parser, fieldName, normal); break;
89+
case FM_shared: shared = JsonReader.readUnsignedLongField(parser, fieldName, shared); break;
10890
default:
10991
throw new AssertionError("bad index: " + fi + ", field = \"" + fieldName + "\"");
11092
}
@@ -163,7 +145,7 @@ public final DbxAccountInfo read(JsonParser parser)
163145
int fi = FM.get(fieldName);
164146
switch (fi) {
165147
case -1: JsonReader.skipValue(parser); break;
166-
case FM_uid: uid = JsonReader.extractUnsignedLongField(parser, fieldName, uid); break;
148+
case FM_uid: uid = JsonReader.readUnsignedLongField(parser, fieldName, uid); break;
167149
case FM_display_name: display_name = JsonReader.StringReader.readField(parser, fieldName, display_name); break;
168150
case FM_country: country = JsonReader.StringReader.readField(parser, fieldName, country); break;
169151
case FM_referral_link: referral_link = JsonReader.StringReader.readField(parser, fieldName, referral_link); break;

src/com/dropbox/core/DbxAppInfo.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.dropbox.core.json.JsonReadException;
77
import com.dropbox.core.json.JsonReader;
88
import com.dropbox.core.util.DumpWriter;
9+
import com.dropbox.core.util.Dumpable;
910

1011
import com.fasterxml.jackson.core.JsonLocation;
1112
import com.fasterxml.jackson.core.JsonParseException;
@@ -15,7 +16,7 @@
1516
/**
1617
* Identifying information about your application.
1718
*/
18-
public class DbxAppInfo extends DbxDataObject implements java.io.Serializable
19+
public class DbxAppInfo extends Dumpable implements java.io.Serializable
1920
{
2021
public static final long serialVersionUID = 0;
2122

@@ -75,11 +76,8 @@ public DbxAppInfo(String key, String secret, DbxHost host)
7576
@Override
7677
protected void dumpFields(DumpWriter out)
7778
{
78-
out.field("key");
79-
dump(out, key);
80-
81-
out.field("secret");
82-
dump(out, secret);
79+
out.field("key", key);
80+
out.field("secret", secret);
8381
}
8482

8583
/**

0 commit comments

Comments
 (0)