Skip to content

Instantly share code, notes, and snippets.

@SubscribeEvent
public void chatEvent(ServerChatEvent event) {
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileLock;
import java.nio.channels.OverlappingFileLockException;
import static com.google.common.base.Preconditions.checkNotNull;
public class FileSystemLock {
private final File lockFile;
07-03 10:05:40.460 8676-12845/com.lovingishard.loveothers D/HttpTransport: -------------- REQUEST --------------
POST https://accounts.google.com/o/oauth2/token
Accept-Encoding: gzip
User-Agent: Google-HTTP-Java-Client/1.15.0-rc (gzip)
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Content-Length: 584
07-03 10:05:40.460 8676-12845/com.lovingishard.loveothers D/HttpTransport: curl -v --compressed -X POST -H 'Accept-Encoding: gzip' -H 'User-Agent: Google-HTTP-Java-Client/1.15.0-rc (gzip)' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -d '@-' -- 'https://accounts.google.com/o/oauth2/token' << $$$
07-03 10:05:40.695 8676-12845/com.lovingishard.loveothers D/HttpTransport: Total: 584 bytes
07-03 10:05:40.695 8676-12845/com.lovingishard.loveothers D/HttpTransport: grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb
E/com.lovingishard.loveothers.MainActivity$2$1: Exception while sending love report
java.io.IOException: unexpected end of stream
at libcore.net.http.FixedLengthOutputStream.close(FixedLengthOutputStream.java:58)
at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:81)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:960)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:410)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
at com.lovingishard.loveothers.MainActivity$2$1.tryUpload(MainActivity.java:174)
at com.lovingishard.loveothers.MainActivity$2$1.doInBackground(MainActivity.java:117)
HttpTransport httpTransport = new NetHttpTransport();
JsonFactory jsonFactory = new GsonFactory();
InputStream p12File = getResources().openRawResource(R.raw.googleapi_privatekey);
PrivateKey privateKey = SecurityUtils.loadPrivateKeyFromKeyStore(
SecurityUtils.getPkcs12KeyStore(), p12File, "notasecret",
"privatekey", "notasecret");
// service account credential (uncomment setServiceAccountUser for domain-wide delegation)
GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport)
.setJsonFactory(jsonFactory)
06-24 05:19:11.505 5030-5068/com.lovingishard.beams D/HttpTransport: -------------- REQUEST --------------
POST https://www.googleapis.com/upload/fusiontables/v1/tables/1VBr-SPlIaSkjevU8M-Y9NCMtzD_7MOldSPJPM-g/import?delimiter=%00&uploadType=resumable
Accept-Encoding: gzip
Authorization: <Not Logged>
User-Agent: lovingishard-beams/1.0 Google-HTTP-Java-Client/1.15.0-rc (gzip)
x-upload-content-type: application/octet-stream
x-upload-content-length: 51
Content-Length: 0
06-24 05:19:11.505 5030-5068/com.lovingishard.beams D/HttpTransport: curl -v --compressed -X POST -H 'Accept-Encoding: gzip' -H 'Authorization: <Not Logged>' -H 'User-Agent: lovingishard-beams/1.0 Google-HTTP-Java-Client/1.15.0-rc (gzip)' -H 'x-upload-content-type: application/octet-stream' -H 'x-upload-content-length: 51' -d '@-' -- 'https://www.googleapis.com/upload/fusiontables/v1/tables/1VBr-SPlIaSkjevU8M-Y9NCMtzD_7MOldSPJPM-g/import?delimiter=%00&uploadType=resuma
GoogleAccountCredential credential = new GoogleAccountCredential(this, "oauth2:" + FusiontablesScopes.FUSIONTABLES);
JsonFactory jsonFactory = new GsonFactory();
HttpTransport transport = AndroidHttp.newCompatibleTransport();
fusiontables = new Fusiontables.Builder(transport, jsonFactory, credential).setApplicationName(appName).build();
Fusiontables.Table.ImportRows cmd = fusiontables.table().importRows(tableId, content);
cmd.setDelimiter("\0");
FusiontablesImport result = cmd.execute(); // Hangs here
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
throw new AssertionError("Use only by binding");
}
protected AbstractGoogleJsonClientRequest(AbstractGoogleJsonClient abstractGoogleJsonClient,
String requestMethod, String uriTemplate, Object jsonContent, Class<T> responseClass) {
super(abstractGoogleJsonClient, requestMethod, uriTemplate, jsonContent == null ? null
: new JsonHttpContent(abstractGoogleJsonClient.getJsonFactory(), jsonContent)
.setWrapperKey(abstractGoogleJsonClient.getObjectParser().getWrapperKeys().isEmpty()
? null : "data"), responseClass);
this.jsonContent = jsonContent;
}
protected AbstractGoogleJsonClientRequest(AbstractGoogleJsonClient abstractGoogleJsonClient,
String requestMethod, String uriTemplate, Object jsonContent, Class<T> responseClass) {
super(abstractGoogleJsonClient, requestMethod, uriTemplate, jsonContent == null ? null
: new JsonHttpContent(abstractGoogleJsonClient.getJsonFactory(), jsonContent)
.setWrapperKey(abstractGoogleJsonClient.getObjectParser().getWrapperKeys().isEmpty()
? null : "data"), responseClass);
this.jsonContent = jsonContent;
}