Skip to content

Commit 478e870

Browse files
author
Lucas McDonald
committed
m
1 parent 62028e1 commit 478e870

File tree

1 file changed

+0
-29
lines changed

1 file changed

+0
-29
lines changed

src/main/java/software/amazon/encryption/s3/internal/CipherSubscriber.java

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -38,114 +38,85 @@ public class CipherSubscriber implements Subscriber<ByteBuffer> {
3838

3939
@Override
4040
public void onSubscribe(Subscription s) {
41-
System.out.println("[CipherSubscriber] onSubscribe called with subscription: " + s);
4241
wrappedSubscriber.onSubscribe(new Subscription() {
4342
@Override
4443
public void request(long n) {
45-
System.out.println("[CipherSubscriber] New request received for " + n + " items");
4644
s.request(n);
4745
}
4846

4947
@Override
5048
public void cancel() {
51-
System.out.println("[CipherSubscriber] Subscription cancelled");
5249
s.cancel();
5350
}
5451
});
5552
}
5653

5754
@Override
5855
public void onNext(ByteBuffer byteBuffer) {
59-
System.out.println("[CipherSubscriber] onNext called with buffer size: " + byteBuffer.remaining());
60-
System.out.println("[CipherSubscriber] isLastPart: " + isLastPart);
6156
int amountToReadFromByteBuffer = getAmountToReadFromByteBuffer(byteBuffer);
62-
System.out.println("[CipherSubscriber] amountToReadFromByteBuffer: " + amountToReadFromByteBuffer);
6357

6458
if (amountToReadFromByteBuffer > 0) {
65-
System.out.println("[CipherSubscriber] Processing chunk of size: " + amountToReadFromByteBuffer);
6659
byte[] buf = BinaryUtils.copyBytesFrom(byteBuffer, amountToReadFromByteBuffer);
67-
System.out.println("[CipherSubscriber] Copied " + buf.length + " bytes from input buffer");
68-
6960
outputBuffer = cipher.update(buf, 0, amountToReadFromByteBuffer);
70-
System.out.println("[CipherSubscriber] Cipher update produced output buffer of length: " + (outputBuffer != null ? outputBuffer.length : 0));
7161

7262
if (outputBuffer == null || outputBuffer.length == 0) {
73-
System.out.println("[CipherSubscriber] No output from cipher update");
7463
// No bytes provided from upstream; to avoid blocking, send an empty buffer to the wrapped subscriber.
7564
wrappedSubscriber.onNext(ByteBuffer.allocate(0));
7665
} else {
7766
boolean atEnd = isLastPart && contentRead.get() + amountToReadFromByteBuffer >= contentLength;
78-
System.out.println("[CipherSubscriber] atEnd: " + atEnd + " (contentRead: " + contentRead.get() + ", contentLength: " + contentLength + ")");
7967

8068
if (atEnd) {
81-
System.out.println("[CipherSubscriber] Processing final bytes");
8269
// If all content has been read, send the final bytes in this onNext call.
8370
// The final bytes must be sent with the final onNext call, not during the onComplete call.
8471
byte[] finalBytes;
8572
try {
8673
finalBytes = cipher.doFinal();
8774
finalized = true;
88-
System.out.println("[CipherSubscriber] Cipher doFinal produced " + finalBytes.length + " bytes");
8975
} catch (final GeneralSecurityException exception) {
90-
System.out.println("[CipherSubscriber] Error during doFinal: " + exception.getMessage());
9176
wrappedSubscriber.onError(exception);
9277
throw new S3EncryptionClientSecurityException(exception.getMessage(), exception);
9378
}
9479

9580
// Combine outputBuffer and finalBytes if both exist
9681
byte[] combinedBuffer;
9782
if (outputBuffer != null && outputBuffer.length > 0) {
98-
System.out.println("[CipherSubscriber] Combining outputBuffer (" + outputBuffer.length + " bytes) with finalBytes (" + finalBytes.length + " bytes)");
9983
combinedBuffer = new byte[outputBuffer.length + finalBytes.length];
10084
System.arraycopy(outputBuffer, 0, combinedBuffer, 0, outputBuffer.length);
10185
System.arraycopy(finalBytes, 0, combinedBuffer, outputBuffer.length, finalBytes.length);
102-
System.out.println("[CipherSubscriber] Combined buffer total length: " + combinedBuffer.length);
10386
} else {
104-
System.out.println("[CipherSubscriber] Using only finalBytes (" + finalBytes.length + " bytes)");
10587
combinedBuffer = finalBytes;
10688
}
107-
System.out.println("[CipherSubscriber] Sending combined buffer to wrapped subscriber");
10889
wrappedSubscriber.onNext(ByteBuffer.wrap(combinedBuffer));
10990
} else {
110-
System.out.println("[CipherSubscriber] Sending " + outputBuffer.length + " bytes to wrapped subscriber");
11191
// Not at end; send content so far
11292
wrappedSubscriber.onNext(ByteBuffer.wrap(outputBuffer));
11393
}
11494
}
11595
} else {
116-
System.out.println("[CipherSubscriber] No bytes to read from input buffer, forwarding original buffer");
11796
// Do nothing
11897
wrappedSubscriber.onNext(byteBuffer);
11998
}
12099
}
121100

122101
private int getAmountToReadFromByteBuffer(ByteBuffer byteBuffer) {
123-
System.out.println("[CipherSubscriber] getAmountToReadFromByteBuffer called with buffer remaining: " + byteBuffer.remaining());
124-
System.out.println("[CipherSubscriber] Current contentRead: " + contentRead.get() + ", contentLength: " + contentLength);
125-
126102
// If content length is null, we should include everything in the cipher because the stream is essentially
127103
// unbounded.
128104
if (contentLength == null) {
129-
System.out.println("[CipherSubscriber] No content length specified, reading entire buffer: " + byteBuffer.remaining());
130105
return byteBuffer.remaining();
131106
}
132107

133108
long amountReadSoFar = contentRead.getAndAdd(byteBuffer.remaining());
134109
long amountRemaining = Math.max(0, contentLength - amountReadSoFar);
135-
System.out.println("[CipherSubscriber] amountReadSoFar: " + amountReadSoFar + ", amountRemaining: " + amountRemaining);
136110

137111
if (amountRemaining > byteBuffer.remaining()) {
138-
System.out.println("[CipherSubscriber] More remaining than buffer size, reading entire buffer: " + byteBuffer.remaining());
139112
return byteBuffer.remaining();
140113
} else {
141-
System.out.println("[CipherSubscriber] Reading partial buffer: " + amountRemaining);
142114
return Math.toIntExact(amountRemaining);
143115
}
144116
}
145117

146118
@Override
147119
public void onError(Throwable t) {
148-
System.out.println("[CipherSubscriber] onError called: " + t.getMessage());
149120
wrappedSubscriber.onError(t);
150121
}
151122

0 commit comments

Comments
 (0)