private boolean isDestructable(final ContentClaim claim) { if (claim == null) { return false; } final ResourceClaim resourceClaim = claim.getResourceClaim(); if (resourceClaim == null) { return false; } return !resourceClaim.isInUse(); }
boolean archive(final ResourceClaim claim) throws IOException { if (!archiveData) { return false; } if (claim.isInUse()) { return false; } // If the claim count is decremented to 0 (<= 0 as a 'defensive programming' strategy), ensure that // we close the stream if there is one. There may be a stream open if create() is called and then // claimant count is removed without writing to the claim (or more specifically, without closing the // OutputStream that is returned when calling write() ). final OutputStream out = writableClaimStreams.remove(claim); if (out != null) { try { out.close(); } catch (final IOException ioe) { LOG.warn("Unable to close Output Stream for " + claim, ioe); } } final Path curPath = getPath(claim); if (curPath == null) { return false; } final boolean archived = archive(curPath); LOG.debug("Successfully moved {} to archive", claim); return archived; }
private boolean remove(final ResourceClaim claim) { if (claim == null) { return false; } // If the claim is still in use, we won't remove it. if (claim.isInUse()) { return false; } Path path = null; try { path = getPath(claim); } catch (final ContentNotFoundException cnfe) { } // Ensure that we have no writable claim streams for this resource claim final ByteCountingOutputStream bcos = writableClaimStreams.remove(claim); if (bcos != null) { try { bcos.close(); } catch (final IOException e) { LOG.warn("Failed to close Output Stream for {} due to {}", claim, e); } } final File file = path.toFile(); if (!file.delete() && file.exists()) { LOG.warn("Unable to delete {} at path {}", new Object[]{claim, path}); return false; } return true; }