diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/VolatileContentRepository.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/VolatileContentRepository.java index 597186547c..e35a63c93e 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/VolatileContentRepository.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/VolatileContentRepository.java @@ -419,7 +419,7 @@ public class VolatileContentRepository implements ContentRepository { } final ContentClaim backupClaim = getBackupClaim(claim); - return (backupClaim == null) ? getContent(claim).getSize() : getBackupRepository().size(claim); + return backupClaim == null ? getContent(claim).getSize() : getBackupRepository().size(claim); } @Override @@ -429,13 +429,13 @@ public class VolatileContentRepository implements ContentRepository { } final ContentClaim backupClaim = getBackupClaim(claim); - return (backupClaim == null) ? getContent(claim).read() : getBackupRepository().read(backupClaim); + return backupClaim == null ? getContent(claim).read() : getBackupRepository().read(backupClaim); } @Override public OutputStream write(final ContentClaim claim) throws IOException { final ContentClaim backupClaim = getBackupClaim(claim); - return (backupClaim == null) ? getContent(claim).write() : getBackupRepository().write(backupClaim); + return backupClaim == null ? getContent(claim).write() : getBackupRepository().write(backupClaim); } @Override @@ -481,8 +481,13 @@ public class VolatileContentRepository implements ContentRepository { @Override public void write(int b) throws IOException { try { + final long bufferLengthBefore = getBufferLength(); super.write(b); - repoSizeCounter.incrementAndGet(); + final long bufferLengthAfter = getBufferLength(); + final long bufferSpaceAdded = bufferLengthAfter - bufferLengthBefore; + if (bufferSpaceAdded > 0) { + repoSizeCounter.addAndGet(bufferSpaceAdded); + } } catch (final IOException e) { final byte[] buff = new byte[1]; buff[0] = (byte) (b & 0xFF); @@ -498,8 +503,13 @@ public class VolatileContentRepository implements ContentRepository { @Override public void write(byte[] b, int off, int len) throws IOException { try { + final long bufferLengthBefore = getBufferLength(); 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) { redirect(b, off, len); }