public void create(String store) throws IBlobStore.Error { try { s3client.createBucket(store); } catch (AmazonServiceException e) { if (e.getStatusCode() == 403) throw new IBlobStore.AuthError("" + e); throw new IBlobStore.IOError("" + e); } catch (AmazonClientException e) { throw new IBlobStore.IOError("" + e); } }
public boolean storeExists(String store) throws IBlobStore.Error { try { s3client.listObjects(store); return true; } catch (final AmazonServiceException e) { if (e.getStatusCode() == 404) return false; if (e.getStatusCode() == 403) throw new IBlobStore.AuthError("" + e); throw new IBlobStore.IOError("" + e); } catch (AmazonClientException e) { Log.v(TAG, "Error: " + e); throw new IBlobStore.IOError("" + e); } }
public void put(String store, String name, ByteBuffer data) throws IBlobStore.Error { InputStream is; ObjectMetadata om; try { is = new ByteArrayInputStream(data.array(), 0, data.limit()); om = new ObjectMetadata(); om.setContentLength(data.limit()); Log.v(TAG, "Content Length:" + data.limit()); om.setContentType("plain/text"); s3client.putObject(store, name, is, om); } catch (AmazonServiceException e) { if (e.getStatusCode() == 403) throw new IBlobStore.AuthError("" + e); throw new IBlobStore.IOError("" + e); } catch (AmazonClientException e) { throw new IBlobStore.IOError("" + e); } }
public ByteBuffer get(String store, String name) throws IBlobStore.Error { try { S3Object result = s3client.getObject(store, name); long length = result.getObjectMetadata().getContentLength(); S3ObjectInputStream is = result.getObjectContent(); Log.v(TAG, " length: " + length); if (length > 1024 * 1024) throw new IBlobStore.IOError("data is too big"); byte[] buf = new byte[(int) length]; is.read(buf); is.close(); return ByteBuffer.wrap(buf); } catch (IOException e) { throw new IBlobStore.IOError("" + e); } catch (AmazonServiceException e) { if (e.getStatusCode() == 403) throw new IBlobStore.AuthError("" + e); if (e.getStatusCode() == 404) throw new IBlobStore.NotFoundError("" + e); throw new IBlobStore.IOError("" + e); } catch (AmazonClientException e) { throw new IBlobStore.IOError("" + e); } }