@Override public long getLength(DataIdentifier identifier) throws DataStoreException { File file = getFile(identifier); if (file.isFile()) { return file.length(); } throw new DataStoreException("Could not length of dataIdentifier [" + identifier + "]"); }
@Override public long getLength(DataIdentifier identifier) throws DataStoreException { File file = getFile(identifier); if (file.isFile()) { return file.length(); } throw new DataStoreException("Could not length of dataIdentifier [" + identifier + "]"); }
@Override public long getLength(DataIdentifier identifier) throws DataStoreException { File file = getFile(identifier); if (file.isFile()) { return file.length(); } throw new DataStoreException("Could not length of dataIdentifier [" + identifier + "]"); }
@Override public boolean exists(DataIdentifier identifier, boolean touch) throws DataStoreException { File file = getFile(identifier); if (file.isFile()) { if (touch) { long now = System.currentTimeMillis(); setLastModified(file, now + ACCESS_TIME_RESOLUTION); } return true; } return false; }
@Override public boolean exists(DataIdentifier identifier, boolean touch) throws DataStoreException { File file = getFile(identifier); if (file.isFile()) { if (touch) { long now = System.currentTimeMillis(); setLastModified(file, now + ACCESS_TIME_RESOLUTION); } return true; } return false; }
@Override public boolean exists(DataIdentifier identifier, boolean touch) throws DataStoreException { File file = getFile(identifier); if (file.isFile()) { if (touch) { long now = System.currentTimeMillis(); setLastModified(file, now + ACCESS_TIME_RESOLUTION); } return true; } return false; }
@Override public void deleteRecord(DataIdentifier identifier) throws DataStoreException { File file = getFile(identifier); synchronized (this) { if (file.exists()) { if (file.delete()) { deleteEmptyParentDirs(file); } else { LOG.warn("Failed to delete file " + file.getAbsolutePath()); } } } }
@Override public void deleteRecord(DataIdentifier identifier) throws DataStoreException { File file = getFile(identifier); synchronized (this) { if (file.exists()) { if (file.delete()) { deleteEmptyParentDirs(file); } else { LOG.warn("Failed to delete file " + file.getAbsolutePath()); } } } }
@Override public void deleteRecord(DataIdentifier identifier) throws DataStoreException { File file = getFile(identifier); synchronized (this) { if (file.exists()) { if (file.delete()) { deleteEmptyParentDirs(file); } else { LOG.warn("Failed to delete file " + file.getAbsolutePath()); } } } }
@Override public long getLastModified(DataIdentifier identifier) throws DataStoreException { long start = System.currentTimeMillis(); File f = getFile(identifier); if (f.isFile()) { return getLastModified(f); } LOG.info("getLastModified:Identifier [{}] not found. Took [{}] ms.", identifier, (System.currentTimeMillis() - start)); throw new DataStoreException("Identifier [" + identifier + "] not found."); }
@Override public long getLastModified(DataIdentifier identifier) throws DataStoreException { long start = System.currentTimeMillis(); File f = getFile(identifier); if (f.isFile()) { return getLastModified(f); } LOG.info("getLastModified:Identifier [{}] not found. Took [{}] ms.", identifier, (System.currentTimeMillis() - start)); throw new DataStoreException("Identifier [" + identifier + "] not found."); }
@Override public long getLastModified(DataIdentifier identifier) throws DataStoreException { long start = System.currentTimeMillis(); File f = getFile(identifier); if (f.isFile()) { return getLastModified(f); } LOG.info("getLastModified:Identifier [{}] not found. Took [{}] ms.", identifier, (System.currentTimeMillis() - start)); throw new DataStoreException("Identifier [" + identifier + "] not found."); }
@Override public InputStream read(DataIdentifier identifier) throws DataStoreException { File file = getFile(identifier); try { return new LazyFileInputStream(file); } catch (IOException e) { throw new DataStoreException("Error opening input stream of " + file.getAbsolutePath(), e); } }
@Override public InputStream read(DataIdentifier identifier) throws DataStoreException { File file = getFile(identifier); try { return new LazyFileInputStream(file); } catch (IOException e) { throw new DataStoreException("Error opening input stream of " + file.getAbsolutePath(), e); } }
@Override public void touch(DataIdentifier identifier, long minModifiedDate) throws DataStoreException { File file = getFile(identifier); long now = System.currentTimeMillis(); if (minModifiedDate > 0 && minModifiedDate > getLastModified(file)) { setLastModified(file, now + ACCESS_TIME_RESOLUTION); } }
@Override public void touch(DataIdentifier identifier, long minModifiedDate) throws DataStoreException { File file = getFile(identifier); long now = System.currentTimeMillis(); if (minModifiedDate > 0 && minModifiedDate > getLastModified(file)) { setLastModified(file, now + ACCESS_TIME_RESOLUTION); } }
@Override public InputStream read(DataIdentifier identifier) throws DataStoreException { File file = getFile(identifier); try { return new LazyFileInputStream(file); } catch (IOException e) { throw new DataStoreException("Error opening input stream of " + file.getAbsolutePath(), e); } }
@Override public void touch(DataIdentifier identifier, long minModifiedDate) throws DataStoreException { File file = getFile(identifier); long now = System.currentTimeMillis(); if (minModifiedDate > 0 && minModifiedDate > getLastModified(file)) { setLastModified(file, now + ACCESS_TIME_RESOLUTION); } }
@Override public void write(DataIdentifier identifier, File src) throws DataStoreException { File dest = getFile(identifier); synchronized (this) { if (dest.exists()) { long now = System.currentTimeMillis(); if (getLastModified(dest) < now + ACCESS_TIME_RESOLUTION) { setLastModified(dest, now + ACCESS_TIME_RESOLUTION); } } else { try { FileUtils.copyFile(src, dest); } catch (IOException ioe) { LOG.error("failed to copy [{}] to [{}]", src.getAbsolutePath(), dest.getAbsolutePath()); throw new DataStoreException("Not able to write file [" + identifier + "]", ioe); } } } }
@Override public void write(DataIdentifier identifier, File src) throws DataStoreException { File dest = getFile(identifier); synchronized (this) { if (dest.exists()) { long now = System.currentTimeMillis(); if (getLastModified(dest) < now + ACCESS_TIME_RESOLUTION) { setLastModified(dest, now + ACCESS_TIME_RESOLUTION); } } else { try { FileUtils.copyFile(src, dest); } catch (IOException ioe) { LOG.error("failed to copy [{}] to [{}]", src.getAbsolutePath(), dest.getAbsolutePath()); throw new DataStoreException("Not able to write file [" + identifier + "]", ioe); } } } }