Skip to content

Commit 7f7bc85

Browse files
committed
Fix checkstyle issues (line lengths).
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@1378928 13f79535-47bb-0310-9956-ffa450edef68
1 parent aead18a commit 7f7bc85

2 files changed

Lines changed: 49 additions & 34 deletions

File tree

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

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@
3636
* </ul>
3737
* </p>
3838
* <p>
39-
* Since this class operates directly on byte streams, and not character streams, it is hard-coded to only encode/decode
40-
* character encodings which are compatible with the lower 127 ASCII chart (ISO-8859-1, Windows-1252, UTF-8, etc).
39+
* Since this class operates directly on byte streams, and not character streams, it is hard-coded to only
40+
* encode/decode character encodings which are compatible with the lower 127 ASCII chart (ISO-8859-1, Windows-1252,
41+
* UTF-8, etc).
4142
* </p>
4243
* <p>
4344
* This class is thread-safe.
@@ -98,8 +99,8 @@ public class Base64 extends BaseNCodec {
9899
};
99100

100101
/**
101-
* This array is a lookup table that translates Unicode characters drawn from the "Base64 Alphabet" (as specified in
102-
* Table 1 of RFC 2045) into their 6-bit positive integer equivalents. Characters that are not in the Base64
102+
* This array is a lookup table that translates Unicode characters drawn from the "Base64 Alphabet" (as specified
103+
* in Table 1 of RFC 2045) into their 6-bit positive integer equivalents. Characters that are not in the Base64
103104
* alphabet but fall within the bounds of the array are translated to -1.
104105
*
105106
* Note: '+' and '-' both decode to 62. '/' and '_' both decode to 63. This means decoder seamlessly handles both
@@ -172,16 +173,16 @@ public Base64() {
172173
/**
173174
* Creates a Base64 codec used for decoding (all modes) and encoding in the given URL-safe mode.
174175
* <p>
175-
* When encoding the line length is 76, the line separator is CRLF, and the encoding table is STANDARD_ENCODE_TABLE.
176+
* When encoding the line length is 76, the line separator is CRLF, and the encoding table is
177+
* STANDARD_ENCODE_TABLE.
176178
* </p>
177179
*
178180
* <p>
179181
* When decoding all variants are supported.
180182
* </p>
181183
*
182184
* @param urlSafe
183-
* if {@code true}, URL-safe encoding is used. In most cases this should be set to
184-
* {@code false}.
185+
* if {@code true}, URL-safe encoding is used. In most cases this should be set to {@code false}.
185186
* @since 1.4
186187
*/
187188
public Base64(boolean urlSafe) {
@@ -202,8 +203,9 @@ public Base64(boolean urlSafe) {
202203
* </p>
203204
*
204205
* @param lineLength
205-
* Each line of encoded data will be at most of the given length (rounded down to nearest multiple of 4).
206-
* If lineLength <= 0, then the output will not be divided into lines (chunks). Ignored when decoding.
206+
* Each line of encoded data will be at most of the given length (rounded down to nearest multiple of
207+
* 4). If lineLength <= 0, then the output will not be divided into lines (chunks). Ignored when
208+
* decoding.
207209
* @since 1.4
208210
*/
209211
public Base64(int lineLength) {
@@ -224,8 +226,9 @@ public Base64(int lineLength) {
224226
* </p>
225227
*
226228
* @param lineLength
227-
* Each line of encoded data will be at most of the given length (rounded down to nearest multiple of 4).
228-
* If lineLength <= 0, then the output will not be divided into lines (chunks). Ignored when decoding.
229+
* Each line of encoded data will be at most of the given length (rounded down to nearest multiple of
230+
* 4). If lineLength <= 0, then the output will not be divided into lines (chunks). Ignored when
231+
* decoding.
229232
* @param lineSeparator
230233
* Each line of encoded data will end with this sequence of bytes.
231234
* @throws IllegalArgumentException
@@ -250,8 +253,9 @@ public Base64(int lineLength, byte[] lineSeparator) {
250253
* </p>
251254
*
252255
* @param lineLength
253-
* Each line of encoded data will be at most of the given length (rounded down to nearest multiple of 4).
254-
* If lineLength <= 0, then the output will not be divided into lines (chunks). Ignored when decoding.
256+
* Each line of encoded data will be at most of the given length (rounded down to nearest multiple of
257+
* 4). If lineLength <= 0, then the output will not be divided into lines (chunks). Ignored when
258+
* decoding.
255259
* @param lineSeparator
256260
* Each line of encoded data will end with this sequence of bytes.
257261
* @param urlSafe
@@ -315,7 +319,8 @@ public boolean isUrlSafe() {
315319
* Position to start reading data from.
316320
* @param inAvail
317321
* Amount of bytes available from input for encoding.
318-
* @param context the context to be used
322+
* @param context
323+
* the context to be used
319324
*/
320325
@Override
321326
void encode(byte[] in, int inPos, int inAvail, Context context) {
@@ -333,8 +338,10 @@ void encode(byte[] in, int inPos, int inAvail, Context context) {
333338
int savedPos = context.pos;
334339
switch (context.modulus) { // 0-2
335340
case 1 : // 8 bits = 6 + 2
336-
context.buffer[context.pos++] = encodeTable[(context.ibitWorkArea >> 2) & MASK_6BITS]; // top 6 bits
337-
context.buffer[context.pos++] = encodeTable[(context.ibitWorkArea << 4) & MASK_6BITS]; // remaining 2
341+
// top 6 bits:
342+
context.buffer[context.pos++] = encodeTable[(context.ibitWorkArea >> 2) & MASK_6BITS];
343+
// remaining 2:
344+
context.buffer[context.pos++] = encodeTable[(context.ibitWorkArea << 4) & MASK_6BITS];
338345
// URL-SAFE skips the padding to further reduce size.
339346
if (encodeTable == STANDARD_ENCODE_TABLE) {
340347
context.buffer[context.pos++] = PAD;
@@ -405,7 +412,8 @@ void encode(byte[] in, int inPos, int inAvail, Context context) {
405412
* Position to start reading data from.
406413
* @param inAvail
407414
* Amount of bytes available from input for encoding.
408-
* @param context the context to be used
415+
* @param context
416+
* the context to be used
409417
*/
410418
@Override
411419
void decode(byte[] in, int inPos, int inAvail, Context context) {

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

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ static class Context {
7676
boolean eof;
7777

7878
/**
79-
* Variable tracks how many characters have been written to the current line. Only used when encoding. We use it to
80-
* make sure each encoded line never goes beyond lineLength (if lineLength > 0).
79+
* Variable tracks how many characters have been written to the current line. Only used when encoding. We use
80+
* it to make sure each encoded line never goes beyond lineLength (if lineLength > 0).
8181
*/
8282
int currentLinePos;
8383

8484
/**
85-
* Writes to the buffer only occur after every 3/5 reads when encoding, and every 4/8 reads when decoding.
86-
* This variable helps track that.
85+
* Writes to the buffer only occur after every 3/5 reads when encoding, and every 4/8 reads when decoding. This
86+
* variable helps track that.
8787
*/
8888
int modulus;
8989

@@ -166,10 +166,11 @@ static class Context {
166166
* @param lineLength if &gt; 0, use chunking with a length <code>lineLength</code>
167167
* @param chunkSeparatorLength the chunk separator length, if relevant
168168
*/
169-
protected BaseNCodec(int unencodedBlockSize, int encodedBlockSize, int lineLength, int chunkSeparatorLength){
169+
protected BaseNCodec(int unencodedBlockSize, int encodedBlockSize, int lineLength, int chunkSeparatorLength) {
170170
this.unencodedBlockSize = unencodedBlockSize;
171171
this.encodedBlockSize = encodedBlockSize;
172-
this.lineLength = (lineLength > 0 && chunkSeparatorLength > 0) ? (lineLength / encodedBlockSize) * encodedBlockSize : 0;
172+
final boolean useChunking = lineLength > 0 && chunkSeparatorLength > 0;
173+
this.lineLength = useChunking ? (lineLength / encodedBlockSize) * encodedBlockSize : 0;
173174
this.chunkSeparatorLength = chunkSeparatorLength;
174175
}
175176

@@ -231,19 +232,22 @@ protected void ensureBufferSize(int size, Context context){
231232
}
232233

233234
/**
234-
* Extracts buffered data into the provided byte[] array, starting at position bPos,
235-
* up to a maximum of bAvail bytes. Returns how many bytes were actually extracted.
235+
* Extracts buffered data into the provided byte[] array, starting at position bPos, up to a maximum of bAvail
236+
* bytes. Returns how many bytes were actually extracted.
237+
* <p>
238+
* Package protected for access from I/O streams.
236239
*
237240
* @param b
238241
* byte[] array to extract the buffered data into.
239242
* @param bPos
240243
* position in byte[] array to start extraction at.
241244
* @param bAvail
242245
* amount of bytes we're allowed to extract. We may extract fewer (if fewer are available).
243-
* @param context the context to be used
246+
* @param context
247+
* the context to be used
244248
* @return The number of bytes successfully extracted into the provided byte[] array.
245249
*/
246-
int readResults(byte[] b, int bPos, int bAvail, Context context) { // package protected for access from I/O streams
250+
int readResults(byte[] b, int bPos, int bAvail, Context context) {
247251
if (context.buffer != null) {
248252
int len = Math.min(available(context), bAvail);
249253
System.arraycopy(context.buffer, context.readPos, b, bPos, len);
@@ -276,8 +280,8 @@ protected static boolean isWhiteSpace(byte byteToCheck) {
276280
}
277281

278282
/**
279-
* Encodes an Object using the Base-N algorithm. This method is provided in order to satisfy the requirements of the
280-
* Encoder interface, and will throw an EncoderException if the supplied object is not of type byte[].
283+
* Encodes an Object using the Base-N algorithm. This method is provided in order to satisfy the requirements of
284+
* the Encoder interface, and will throw an EncoderException if the supplied object is not of type byte[].
281285
*
282286
* @param obj
283287
* Object to encode
@@ -317,12 +321,13 @@ public String encodeAsString(byte[] pArray){
317321
}
318322

319323
/**
320-
* Decodes an Object using the Base-N algorithm. This method is provided in order to satisfy the requirements of the
321-
* Decoder interface, and will throw a DecoderException if the supplied object is not of type byte[] or String.
324+
* Decodes an Object using the Base-N algorithm. This method is provided in order to satisfy the requirements of
325+
* the Decoder interface, and will throw a DecoderException if the supplied object is not of type byte[] or String.
322326
*
323327
* @param obj
324328
* Object to decode
325-
* @return An object (of type byte[]) containing the binary data which corresponds to the byte[] or String supplied.
329+
* @return An object (of type byte[]) containing the binary data which corresponds to the byte[] or String
330+
* supplied.
326331
* @throws DecoderException
327332
* if the parameter supplied is not of type byte[]
328333
*/
@@ -388,9 +393,11 @@ public byte[] encode(byte[] pArray) {
388393
return buf;
389394
}
390395

391-
abstract void encode(byte[] pArray, int i, int length, Context context); // package protected for access from I/O streams
396+
// package protected for access from I/O streams
397+
abstract void encode(byte[] pArray, int i, int length, Context context);
392398

393-
abstract void decode(byte[] pArray, int i, int length, Context context); // package protected for access from I/O streams
399+
// package protected for access from I/O streams
400+
abstract void decode(byte[] pArray, int i, int length, Context context);
394401

395402
/**
396403
* Returns whether or not the <code>octet</code> is in the current alphabet.

0 commit comments

Comments
 (0)