@Override public BlobStore create(Closer closer) { return new FileBlobStore(directory); }
@Override protected byte[] readBlockFromBackend(BlockId id) throws IOException { File f = getFile(id.digest, false); if (!f.exists()) { File old = getFile(id.digest, true); f.getParentFile().mkdir(); old.renameTo(f); f = getFile(id.digest, false); } int length = (int) Math.min(f.length(), getBlockSize()); byte[] data = new byte[length]; InputStream in = new FileInputStream(f); try { IOUtils.skipFully(in, id.pos); IOUtils.readFully(in, data, 0, length); } finally { in.close(); } return data; }
@Override public void setUp() throws IOException { FileUtils.deleteDirectory(new File("target/tempFileBlobStoreTest")); FileBlobStore store = new FileBlobStore("target/tempFileBlobStoreTest"); store.setBlockSize(128); store.setBlockSizeMin(48); this.store = store; }
FileBlobStore fbs = new FileBlobStore(getTestDir("fbs1").getAbsolutePath()); fbs.setReferenceKeyPlainText("foobar"); FileStore fileStoreWithFBS = FileStoreBuilder.fileStoreBuilder(getTestDir("tar2")) .withBlobStore(fbs)
IOUtils.writeVarLong(idStream, length); byte[] digest = messageDigest.digest(); File f = getFile(digest, false); if (f.exists()) { file.delete(); byte[] id = idStream.toByteArray(); String blobId = StringUtils.convertBytesToHex(id); usesBlobId(blobId); return blobId;
@Override public void startMark() throws IOException { mark = true; for (int j = 0; j < 256; j++) { String sub1 = StringUtils.convertBytesToHex(new byte[] { (byte) j }); File x = new File(baseDir, sub1); for (int i = 0; i < 256; i++) { String sub2 = StringUtils.convertBytesToHex(new byte[] { (byte) i }); File d = new File(x, sub2); File old = new File(x, sub2 + OLD_SUFFIX); if (d.exists()) { if (old.exists()) { for (File p : d.listFiles()) { String name = p.getName(); File newName = new File(old, name); p.renameTo(newName); } } else { d.renameTo(old); } } } } markInUse(); }
IOUtils.writeVarLong(idStream, length); byte[] digest = messageDigest.digest(); File f = getFile(digest, false); if (f.exists()) { file.delete(); byte[] id = idStream.toByteArray(); String blobId = StringUtils.convertBytesToHex(id); usesBlobId(blobId); return blobId;
@Override public void startMark() throws IOException { mark = true; for (int j = 0; j < 256; j++) { String sub1 = StringUtils.convertBytesToHex(new byte[] { (byte) j }); File x = new File(baseDir, sub1); for (int i = 0; i < 256; i++) { String sub2 = StringUtils.convertBytesToHex(new byte[] { (byte) i }); File d = new File(x, sub2); File old = new File(x, sub2 + OLD_SUFFIX); if (d.exists()) { if (old.exists()) { for (File p : d.listFiles()) { String name = p.getName(); File newName = new File(old, name); p.renameTo(newName); } } else { d.renameTo(old); } } } } markInUse(); }
@Override public BlobStore create(Closer closer) { return new FileBlobStore(directory); }
@Override protected byte[] readBlockFromBackend(BlockId id) throws IOException { File f = getFile(id.digest, false); if (!f.exists()) { File old = getFile(id.digest, true); f.getParentFile().mkdir(); old.renameTo(f); f = getFile(id.digest, false); } int length = (int) Math.min(f.length(), getBlockSize()); byte[] data = new byte[length]; InputStream in = new FileInputStream(f); try { IOUtils.skipFully(in, id.pos); IOUtils.readFully(in, data, 0, length); } finally { in.close(); } return data; }
IOUtils.writeVarLong(idStream, length); byte[] digest = messageDigest.digest(); File f = getFile(digest, false); if (f.exists()) { file.delete(); byte[] id = idStream.toByteArray(); String blobId = StringUtils.convertBytesToHex(id); usesBlobId(blobId); return blobId;
@Override public void startMark() throws IOException { mark = true; for (int j = 0; j < 256; j++) { String sub1 = StringUtils.convertBytesToHex(new byte[] { (byte) j }); File x = new File(baseDir, sub1); for (int i = 0; i < 256; i++) { String sub2 = StringUtils.convertBytesToHex(new byte[] { (byte) i }); File d = new File(x, sub2); File old = new File(x, sub2 + OLD_SUFFIX); if (d.exists()) { if (old.exists()) { for (File p : d.listFiles()) { String name = p.getName(); File newName = new File(old, name); p.renameTo(newName); } } else { d.renameTo(old); } } } } markInUse(); }
@Override public BlobStore setUp() { storeDir = new File(basedir, unique); fbs = new FileBlobStore(storeDir.getAbsolutePath()); configure(fbs); return fbs; }
@Override protected byte[] readBlockFromBackend(BlockId id) throws IOException { File f = getFile(id.digest, false); if (!f.exists()) { File old = getFile(id.digest, true); f.getParentFile().mkdir(); old.renameTo(f); f = getFile(id.digest, false); } int length = (int) Math.min(f.length(), getBlockSize()); byte[] data = new byte[length]; InputStream in = new FileInputStream(f); try { IOUtils.skipFully(in, id.pos); IOUtils.readFully(in, data, 0, length); } finally { in.close(); } return data; }
@Override public long countDeleteChunks(List<String> chunkIds, long maxLastModifiedTime) throws Exception { int count = 0; for (String chunkId : chunkIds) { byte[] digest = StringUtils.convertHexToBytes(chunkId); File f = getFile(digest, false); if (!f.exists()) { File old = getFile(digest, true); f.getParentFile().mkdir(); old.renameTo(f); f = getFile(digest, false); } if ((maxLastModifiedTime <= 0) || FileUtils.isFileOlder(f, maxLastModifiedTime)) { f.delete(); count++; } } return count; }
@Override public BlobStore setUp() { storeDir = new File(basedir, unique); fbs = new FileBlobStore(storeDir.getAbsolutePath()); configure(fbs); return fbs; }
@Override public long countDeleteChunks(List<String> chunkIds, long maxLastModifiedTime) throws Exception { int count = 0; for (String chunkId : chunkIds) { byte[] digest = StringUtils.convertHexToBytes(chunkId); File f = getFile(digest, false); if (!f.exists()) { File old = getFile(digest, true); f.getParentFile().mkdir(); old.renameTo(f); f = getFile(digest, false); } if ((maxLastModifiedTime <= 0) || FileUtils.isFileOlder(f, maxLastModifiedTime)) { f.delete(); count++; } } return count; }