Skip to content

Commit 114830d

Browse files
committed
Refactor: Use byte[] from ensureBufferSize() instead of always deferencing it from the context.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@1378963 13f79535-47bb-0310-9956-ffa450edef68
1 parent e21c0af commit 114830d

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

  • src/main/java/org/apache/commons/codec/binary

src/main/java/org/apache/commons/codec/binary/Base64.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ void encode(byte[] in, int inPos, int inAvail, Context context) {
334334
if (0 == context.modulus && lineLength == 0) {
335335
return; // no leftovers to process and not using chunking
336336
}
337-
ensureBufferSize(encodeSize, context);
337+
final byte[] buffer = ensureBufferSize(encodeSize, context);
338338
int savedPos = context.pos;
339339
switch (context.modulus) { // 0-2
340340
case 1 : // 8 bits = 6 + 2
@@ -367,7 +367,7 @@ void encode(byte[] in, int inPos, int inAvail, Context context) {
367367
}
368368
} else {
369369
for (int i = 0; i < inAvail; i++) {
370-
ensureBufferSize(encodeSize, context);
370+
final byte[] buffer = ensureBufferSize(encodeSize, context);
371371
context.modulus = (context.modulus+1) % BYTES_PER_UNENCODED_BLOCK;
372372
int b = in[inPos++];
373373
if (b < 0) {
@@ -424,7 +424,7 @@ void decode(byte[] in, int inPos, int inAvail, Context context) {
424424
context.eof = true;
425425
}
426426
for (int i = 0; i < inAvail; i++) {
427-
ensureBufferSize(decodeSize, context);
427+
final byte[] buffer = ensureBufferSize(decodeSize, context);
428428
byte b = in[inPos++];
429429
if (b == PAD) {
430430
// We're done.
@@ -437,9 +437,9 @@ void decode(byte[] in, int inPos, int inAvail, Context context) {
437437
context.modulus = (context.modulus+1) % BYTES_PER_ENCODED_BLOCK;
438438
context.ibitWorkArea = (context.ibitWorkArea << BITS_PER_ENCODED_BYTE) + result;
439439
if (context.modulus == 0) {
440-
context.buffer[context.pos++] = (byte) ((context.ibitWorkArea >> 16) & MASK_8BITS);
441-
context.buffer[context.pos++] = (byte) ((context.ibitWorkArea >> 8) & MASK_8BITS);
442-
context.buffer[context.pos++] = (byte) (context.ibitWorkArea & MASK_8BITS);
440+
buffer[context.pos++] = (byte) ((context.ibitWorkArea >> 16) & MASK_8BITS);
441+
buffer[context.pos++] = (byte) ((context.ibitWorkArea >> 8) & MASK_8BITS);
442+
buffer[context.pos++] = (byte) (context.ibitWorkArea & MASK_8BITS);
443443
}
444444
}
445445
}
@@ -450,7 +450,7 @@ void decode(byte[] in, int inPos, int inAvail, Context context) {
450450
// EOF (-1) and first time '=' character is encountered in stream.
451451
// This approach makes the '=' padding characters completely optional.
452452
if (context.eof && context.modulus != 0) {
453-
ensureBufferSize(decodeSize, context);
453+
final byte[] buffer = ensureBufferSize(decodeSize, context);
454454

455455
// We have some spare bits remaining
456456
// Output all whole multiples of 8 bits and ignore the rest
@@ -459,12 +459,12 @@ void decode(byte[] in, int inPos, int inAvail, Context context) {
459459
// break;
460460
case 2 : // 12 bits = 8 + 4
461461
context.ibitWorkArea = context.ibitWorkArea >> 4; // dump the extra 4 bits
462-
context.buffer[context.pos++] = (byte) ((context.ibitWorkArea) & MASK_8BITS);
462+
buffer[context.pos++] = (byte) ((context.ibitWorkArea) & MASK_8BITS);
463463
break;
464464
case 3 : // 18 bits = 8 + 8 + 2
465465
context.ibitWorkArea = context.ibitWorkArea >> 2; // dump 2 bits
466-
context.buffer[context.pos++] = (byte) ((context.ibitWorkArea >> 8) & MASK_8BITS);
467-
context.buffer[context.pos++] = (byte) ((context.ibitWorkArea) & MASK_8BITS);
466+
buffer[context.pos++] = (byte) ((context.ibitWorkArea >> 8) & MASK_8BITS);
467+
buffer[context.pos++] = (byte) ((context.ibitWorkArea) & MASK_8BITS);
468468
break;
469469
}
470470
}

0 commit comments

Comments
 (0)