while ( read < length ) {
// make sure we don't write past the content-length
int maxRead = (int) Math.min( (long) buffer.length, length - read );
int c = data.read( buffer, 0, maxRead );
if ( c == -1 ) {
throw new EsuException(
"EOF encountered reading data stream" );
}
out.write( buffer, 0, c );
read += c;
}
out.close();
} catch ( IOException e ) {
silentClose( out );
con.disconnect();
throw new EsuException( "Error posting data", e );
}
// Check response
if ( con.getResponseCode() > 299 ) {
handleError( con );
}
con.disconnect();
} catch ( MalformedURLException e ) {
throw new EsuException( "Invalid URL", e );
} catch ( IOException e ) {
throw new EsuException( "Error connecting to server", e );
} catch ( GeneralSecurityException e ) {
throw new EsuException( "Error computing request signature", e );
} catch ( URISyntaxException e ) {
throw new EsuException( "Invalid URL", e );
}
}