@Override FileSystemStore getFileSystemStore() throws IOException { return new Jets3tFileSystemStore(); }
public File retrieveBlock(Block block, long byteRangeStart) throws IOException { File fileBlock = null; InputStream in = null; OutputStream out = null; try { fileBlock = newBackupFile(); in = get(blockToKey(block), byteRangeStart); out = new BufferedOutputStream(new FileOutputStream(fileBlock)); byte[] buf = new byte[bufferSize]; int numRead; while ((numRead = in.read(buf)) >= 0) { out.write(buf, 0, numRead); } return fileBlock; } catch (IOException e) { // close output stream to file then delete file closeQuietly(out); out = null; // to prevent a second close if (fileBlock != null) { fileBlock.delete(); } throw e; } finally { closeQuietly(out); closeQuietly(in); } }
@Override public void deleteBlock(Block block) throws IOException { delete(blockToKey(block)); }
@Override public void storeBlock(Block block, File file) throws IOException { BufferedInputStream in = null; try { in = new BufferedInputStream(new FileInputStream(file)); put(blockToKey(block), in, block.getLength(), false); } finally { closeQuietly(in); } }
public Set<Path> listDeepSubPaths(Path path) throws IOException { try { String prefix = pathToKey(path); if (!prefix.endsWith(PATH_DELIMITER)) { prefix += PATH_DELIMITER; } S3Object[] objects = s3Service.listObjects(bucket, prefix, null); Set<Path> prefixes = new TreeSet<Path>(); for (int i = 0; i < objects.length; i++) { prefixes.add(keyToPath(objects[i].getKey())); } prefixes.remove(path); return prefixes; } catch (S3ServiceException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } }
public boolean blockExists(long blockId) throws IOException { InputStream in = get(blockToKey(blockId), false); if (in == null) { return false; } in.close(); return true; }
public void dump() throws IOException { StringBuilder sb = new StringBuilder("S3 Filesystem, "); sb.append(bucket.getName()).append("\n"); try { S3Object[] objects = s3Service.listObjects(bucket, PATH_DELIMITER, null); for (int i = 0; i < objects.length; i++) { Path path = keyToPath(objects[i].getKey()); sb.append(path).append("\n"); INode m = retrieveINode(path); sb.append("\t").append(m.getFileType()).append("\n"); if (m.getFileType() == FileType.DIRECTORY) { continue; } for (int j = 0; j < m.getBlocks().length; j++) { sb.append("\t").append(m.getBlocks()[j]).append("\n"); } } } catch (S3ServiceException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } System.out.println(sb); }
private InputStream get(String key, boolean checkMetadata) throws IOException { try { S3Object object = s3Service.getObject(bucket.getName(), key); if (checkMetadata) { checkMetadata(object); } return object.getDataInputStream(); } catch (S3ServiceException e) { if ("NoSuchKey".equals(e.getS3ErrorCode())) { throw new IOException(key + " doesn't exist"); } if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } catch (ServiceException e) { handleServiceException(e); return null; } }
private String blockToKey(Block block) { return blockToKey(block.getId()); }
private InputStream get(String key, boolean checkMetadata) throws IOException { try { S3Object object = s3Service.getObject(bucket, key); if (checkMetadata) { checkMetadata(object); } return object.getDataInputStream(); } catch (S3ServiceException e) { if ("NoSuchKey".equals(e.getS3ErrorCode())) { return null; } if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } }
public void storeBlock(Block block, File file) throws IOException { BufferedInputStream in = null; try { in = new BufferedInputStream(new FileInputStream(file)); put(blockToKey(block), in, block.getLength(), false); } finally { closeQuietly(in); } }
public Set<Path> listDeepSubPaths(Path path) throws IOException { try { String prefix = pathToKey(path); if (!prefix.endsWith(PATH_DELIMITER)) { prefix += PATH_DELIMITER; } S3Object[] objects = s3Service.listObjects(bucket, prefix, null); Set<Path> prefixes = new TreeSet<Path>(); for (int i = 0; i < objects.length; i++) { prefixes.add(keyToPath(objects[i].getKey())); } prefixes.remove(path); return prefixes; } catch (S3ServiceException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } }
public boolean blockExists(long blockId) throws IOException { InputStream in = get(blockToKey(blockId), false); if (in == null) { return false; } in.close(); return true; }
public void deleteBlock(Block block) throws IOException { delete(blockToKey(block)); }
public void dump() throws IOException { StringBuilder sb = new StringBuilder("S3 Filesystem, "); sb.append(bucket.getName()).append("\n"); try { S3Object[] objects = s3Service.listObjects(bucket, PATH_DELIMITER, null); for (int i = 0; i < objects.length; i++) { Path path = keyToPath(objects[i].getKey()); sb.append(path).append("\n"); INode m = retrieveINode(path); sb.append("\t").append(m.getFileType()).append("\n"); if (m.getFileType() == FileType.DIRECTORY) { continue; } for (int j = 0; j < m.getBlocks().length; j++) { sb.append("\t").append(m.getBlocks()[j]).append("\n"); } } } catch (S3ServiceException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } System.out.println(sb); }