359 * @param binaryData Array containing binaryData 360 * @return Encoded Base64 array 361 */ 362 /** 363 * Encode a byte array in Base64 format and return an optionally 364 * wrapped line. 365 * 366 * @param binaryData <code>byte[]</code> data to be encoded 367 * @param length <code>int<code> length of wrapped lines; No wrapping if less than 4. 368 * @return a <code>String</code> with encoded data 369 */ 370 public static final String encode(byte[] binaryData,int length) { 371 if (length < 4) { 372 length = Integer.MAX_VALUE; 373 } 374 375 if (binaryData == null) { 376 return null; 377 } 378 379 int lengthDataBits = binaryData.length * EIGHTBIT; 380 if (lengthDataBits == 0) { 381 return ""; 382 } 383 384 int fewerThan24bits = lengthDataBits % TWENTYFOURBITGROUP; 385 int numberTriplets = lengthDataBits / TWENTYFOURBITGROUP; 386 int numberQuartet = fewerThan24bits != 0 ? numberTriplets + 1 : numberTriplets; 387 int quartesPerLine = length / 4; 388 int numberLines = (numberQuartet - 1) / quartesPerLine; 389 char encodedData[] = null; 390 391 encodedData = new char[numberQuartet * 4 + numberLines]; 392 393 byte k = 0, l = 0, b1 = 0, b2 = 0, b3 = 0; 394 int encodedIndex = 0; 395 int dataIndex = 0; 396 int i = 0; 397 398 for (int line = 0; line < numberLines; line++) { 399 for (int quartet = 0; quartet < 19; quartet++) { 400 b1 = binaryData[dataIndex++]; 401 b2 = binaryData[dataIndex++]; 402 b3 = binaryData[dataIndex++]; 403 404 l = (byte)(b2 & 0x0f); 405 k = (byte)(b1 & 0x03); 406 | 359 * @param binaryData Array containing binaryData 360 * @return Encoded Base64 array 361 */ 362 /** 363 * Encode a byte array in Base64 format and return an optionally 364 * wrapped line. 365 * 366 * @param binaryData <code>byte[]</code> data to be encoded 367 * @param length <code>int<code> length of wrapped lines; No wrapping if less than 4. 368 * @return a <code>String</code> with encoded data 369 */ 370 public static final String encode(byte[] binaryData,int length) { 371 if (length < 4) { 372 length = Integer.MAX_VALUE; 373 } 374 375 if (binaryData == null) { 376 return null; 377 } 378 379 long lengthDataBits = ((long) binaryData.length) * ((long) EIGHTBIT); 380 if (lengthDataBits == 0L) { 381 return ""; 382 } 383 384 long fewerThan24bits = lengthDataBits % ((long) TWENTYFOURBITGROUP); 385 int numberTriplets = (int) (lengthDataBits / TWENTYFOURBITGROUP); 386 int numberQuartet = fewerThan24bits != 0L ? numberTriplets + 1 : numberTriplets; 387 int quartesPerLine = length / 4; 388 int numberLines = (numberQuartet - 1) / quartesPerLine; 389 char encodedData[] = null; 390 391 encodedData = new char[numberQuartet * 4 + numberLines]; 392 393 byte k = 0, l = 0, b1 = 0, b2 = 0, b3 = 0; 394 int encodedIndex = 0; 395 int dataIndex = 0; 396 int i = 0; 397 398 for (int line = 0; line < numberLines; line++) { 399 for (int quartet = 0; quartet < 19; quartet++) { 400 b1 = binaryData[dataIndex++]; 401 b2 = binaryData[dataIndex++]; 402 b3 = binaryData[dataIndex++]; 403 404 l = (byte)(b2 & 0x0f); 405 k = (byte)(b1 & 0x03); 406 |