NIFI-230: Fixed bug in calculating how much data has been written to a ContentClaim

This commit is contained in:
Mark Payne 2015-06-18 11:30:04 -04:00
parent b7b42c7423
commit c4d186bdd9
1 changed files with 15 additions and 5 deletions

View File

@ -419,7 +419,7 @@ public class VolatileContentRepository implements ContentRepository {
} }
final ContentClaim backupClaim = getBackupClaim(claim); final ContentClaim backupClaim = getBackupClaim(claim);
return (backupClaim == null) ? getContent(claim).getSize() : getBackupRepository().size(claim); return backupClaim == null ? getContent(claim).getSize() : getBackupRepository().size(claim);
} }
@Override @Override
@ -429,13 +429,13 @@ public class VolatileContentRepository implements ContentRepository {
} }
final ContentClaim backupClaim = getBackupClaim(claim); final ContentClaim backupClaim = getBackupClaim(claim);
return (backupClaim == null) ? getContent(claim).read() : getBackupRepository().read(backupClaim); return backupClaim == null ? getContent(claim).read() : getBackupRepository().read(backupClaim);
} }
@Override @Override
public OutputStream write(final ContentClaim claim) throws IOException { public OutputStream write(final ContentClaim claim) throws IOException {
final ContentClaim backupClaim = getBackupClaim(claim); final ContentClaim backupClaim = getBackupClaim(claim);
return (backupClaim == null) ? getContent(claim).write() : getBackupRepository().write(backupClaim); return backupClaim == null ? getContent(claim).write() : getBackupRepository().write(backupClaim);
} }
@Override @Override
@ -481,8 +481,13 @@ public class VolatileContentRepository implements ContentRepository {
@Override @Override
public void write(int b) throws IOException { public void write(int b) throws IOException {
try { try {
final long bufferLengthBefore = getBufferLength();
super.write(b); super.write(b);
repoSizeCounter.incrementAndGet(); final long bufferLengthAfter = getBufferLength();
final long bufferSpaceAdded = bufferLengthAfter - bufferLengthBefore;
if (bufferSpaceAdded > 0) {
repoSizeCounter.addAndGet(bufferSpaceAdded);
}
} catch (final IOException e) { } catch (final IOException e) {
final byte[] buff = new byte[1]; final byte[] buff = new byte[1];
buff[0] = (byte) (b & 0xFF); buff[0] = (byte) (b & 0xFF);
@ -498,8 +503,13 @@ public class VolatileContentRepository implements ContentRepository {
@Override @Override
public void write(byte[] b, int off, int len) throws IOException { public void write(byte[] b, int off, int len) throws IOException {
try { try {
final long bufferLengthBefore = getBufferLength();
super.write(b, off, len); super.write(b, off, len);
repoSizeCounter.addAndGet(len); final long bufferLengthAfter = getBufferLength();
final long bufferSpaceAdded = bufferLengthAfter - bufferLengthBefore;
if (bufferSpaceAdded > 0) {
repoSizeCounter.addAndGet(bufferSpaceAdded);
}
} catch (final IOException e) { } catch (final IOException e) {
redirect(b, off, len); redirect(b, off, len);
} }