/** * Copy sometimes returns a successful response and starts to send whitespace * characters to us. This method processes those whitespace characters and * will throw an exception if the response is either unknown or an error. * @param response Response object from the PUT request. * @return The response with the input stream drained. * @throws IOException If anything goes wrong. */ private static Response verifyCopy(Response response) throws IOException { if(response.connection.getResponseCode() < 400) { byte[] body=GetResponse.slurpInputStream(response.connection.getInputStream()); String message=new String(body); if(message.contains("<Error")) { throw new IOException(message.substring(message.indexOf("<Error"))); } else if(message.contains("</CopyObjectResult>")) { // It worked! } else { throw new IOException("Unexpected response: " + message); } } return response; }
/** * Pulls a representation of an S3Object out of the HttpURLConnection response. */ public GetResponse(HttpURLConnection connection) throws IOException { super(connection); if(connection.getResponseCode() < 400) { Map metadata=extractMetadata(connection); byte[] body=slurpInputStream(connection.getInputStream()); this.object=new S3Object(body, metadata); } }
/** * Copy sometimes returns a successful response and starts to send whitespace * characters to us. This method processes those whitespace characters and * will throw an exception if the response is either unknown or an error. * @param response Response object from the PUT request. * @return The response with the input stream drained. * @throws IOException If anything goes wrong. */ private static Response verifyCopy(Response response) throws IOException { if(response.connection.getResponseCode() < 400) { byte[] body=GetResponse.slurpInputStream(response.connection.getInputStream()); String message=new String(body); if(message.contains("<Error")) { throw new IOException(message.substring(message.indexOf("<Error"))); } else if(message.contains("</CopyObjectResult>")) { // It worked! } else { throw new IOException("Unexpected response: " + message); } } return response; }
/** * Pulls a representation of an S3Object out of the HttpURLConnection response. */ public GetResponse(HttpURLConnection connection) throws IOException { super(connection); if(connection.getResponseCode() < 400) { Map metadata=extractMetadata(connection); byte[] body=slurpInputStream(connection.getInputStream()); this.object=new S3Object(body, metadata); } }