Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Dias committed Apr 10, 2013
2 parents 4fb77ce + aaf5411 commit 5a274b3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -16,7 +16,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<slf4j.version>1.6.1</slf4j.version>
<neo4j.version>1.9.M04</neo4j.version>
<neo4j.version>1.9.M05</neo4j.version>
<jersey.version>1.4</jersey.version>
<blueprints.version>1.2</blueprints.version>
<gremlin.version>1.5</gremlin.version>
Expand Down
23 changes: 20 additions & 3 deletions src/main/java/org/neo4j/rest/graphdb/ExecutingRestRequest.java
Expand Up @@ -145,17 +145,34 @@ public RequestResult delete(String path) {
public RequestResult post( String path, Object data ) {
Builder builder = builder( path );
if ( data != null ) {
builder = builder.entity( toInputStream(data), APPLICATION_JSON_TYPE );
Object payload = data instanceof InputStream ? data : JsonHelper.createJsonFrom(data);
builder = builder.entity( payload , APPLICATION_JSON_TYPE );
}
return RequestResult.extractFrom(builder.post(ClientResponse.class));
}

private InputStream toInputStream(final Object data) {
try {
if (data instanceof InputStream) return (InputStream) data;
PipedInputStream inputStream = new PipedInputStream(8 * 1024);
final PipedInputStream inputStream = new PipedInputStream(8 * 1024);
final PipedOutputStream outputStream = new PipedOutputStream(inputStream);
pool.submit(new Runnable() { public void run() { StreamJsonHelper.writeJsonTo(data, outputStream); } });
pool.submit(new Runnable() {
public void run() {
StreamJsonHelper.writeJsonTo(data, outputStream);
try {
outputStream.close();
} catch (IOException e) {
System.err.println("Error closing output stream for sent data "+e.getMessage());
// ignore
}
try {
inputStream.close();
} catch (IOException e) {
System.err.println("Error closing input stream for sent data "+e.getMessage());
// ignore
}
}
});
return inputStream;
} catch (IOException e) {
throw new RuntimeException("Error writing "+data+" to stream",e);
Expand Down

0 comments on commit 5a274b3

Please sign in to comment.