use of java.util.Base64.Decoder in project j2objc by google.
the class Base64Test method testRoundTrip_allBytes_mime_lineLength.
/**
* check a range of possible line lengths
*/
public void testRoundTrip_allBytes_mime_lineLength() {
Decoder decoder = Base64.getMimeDecoder();
byte[] separator = new byte[] { '*' };
checkRoundTrip_allBytes(Base64.getMimeEncoder(4, separator), decoder, wrapLines("*", ALL_BYTE_VALUES_ENCODED, 4));
checkRoundTrip_allBytes(Base64.getMimeEncoder(8, separator), decoder, wrapLines("*", ALL_BYTE_VALUES_ENCODED, 8));
checkRoundTrip_allBytes(Base64.getMimeEncoder(20, separator), decoder, wrapLines("*", ALL_BYTE_VALUES_ENCODED, 20));
checkRoundTrip_allBytes(Base64.getMimeEncoder(100, separator), decoder, wrapLines("*", ALL_BYTE_VALUES_ENCODED, 100));
checkRoundTrip_allBytes(Base64.getMimeEncoder(Integer.MAX_VALUE & ~3, separator), decoder, wrapLines("*", ALL_BYTE_VALUES_ENCODED, Integer.MAX_VALUE & ~3));
}
use of java.util.Base64.Decoder in project j2objc by google.
the class Base64Test method testDecoder_decodeArrayToArray.
/**
* Tests {@link Decoder#decode(byte[], byte[])} for correctness as well as
* for consistency with other methods tested elsewhere.
*/
public void testDecoder_decodeArrayToArray() {
Decoder decoder = Base64.getDecoder();
// Empty input
assertEquals(0, decoder.decode(new byte[0], new byte[0]));
// Test data for non-empty input
String inputString = "YWJjZWZnaGk=";
byte[] input = inputString.getBytes(US_ASCII);
String expectedString = "abcefghi";
byte[] decodedBytes = expectedString.getBytes(US_ASCII);
// check test data consistency with other methods that are tested elsewhere
assertRoundTrip(Base64.getEncoder(), decoder, inputString, decodedBytes);
// Non-empty input: output array too short
byte[] tooShort = new byte[decodedBytes.length - 1];
try {
decoder.decode(input, tooShort);
fail();
} catch (IllegalArgumentException expected) {
}
// Non-empty input: output array longer than required
byte[] tooLong = new byte[decodedBytes.length + 1];
int tooLongBytesDecoded = decoder.decode(input, tooLong);
assertEquals(decodedBytes.length, tooLongBytesDecoded);
assertEquals(0, tooLong[tooLong.length - 1]);
assertArrayPrefixEquals(tooLong, decodedBytes.length, decodedBytes);
// Non-empty input: output array has exact minimum required size
byte[] justRight = new byte[decodedBytes.length];
int justRightBytesDecoded = decoder.decode(input, justRight);
assertEquals(decodedBytes.length, justRightBytesDecoded);
assertArrayEquals(decodedBytes, justRight);
}
use of java.util.Base64.Decoder in project j2objc by google.
the class Base64Test method testDecoder_decodeByteBuffer_invalidData.
public void testDecoder_decodeByteBuffer_invalidData() {
Decoder decoder = Base64.getDecoder();
// Test the two types of byte buffer.
String inputString = "AAAA AAAA";
byte[] input = inputString.getBytes(US_ASCII);
ByteBuffer inputBuffer = ByteBuffer.allocate(input.length);
inputBuffer.put(input);
inputBuffer.position(0);
checkDecoder_decodeByteBuffer_invalidData(decoder, inputBuffer);
inputBuffer = ByteBuffer.allocateDirect(input.length);
inputBuffer.put(input);
inputBuffer.position(0);
checkDecoder_decodeByteBuffer_invalidData(decoder, inputBuffer);
}
use of java.util.Base64.Decoder in project j2objc by google.
the class Base64Test method testDecoder_decodeByteBuffer.
public void testDecoder_decodeByteBuffer() {
Decoder decoder = Base64.getDecoder();
byte[] emptyByteArray = new byte[0];
ByteBuffer emptyByteBuffer = ByteBuffer.wrap(emptyByteArray);
ByteBuffer emptyDecodedBuffer = decoder.decode(emptyByteBuffer);
assertEquals(emptyByteBuffer, emptyDecodedBuffer);
assertNotSame(emptyByteArray, emptyDecodedBuffer);
// Test the two types of byte buffer.
String inputString = "YWJjZWZnaGk=";
byte[] input = inputString.getBytes(US_ASCII);
String expectedString = "abcefghi";
byte[] expectedBytes = expectedString.getBytes(US_ASCII);
ByteBuffer inputBuffer = ByteBuffer.allocate(input.length);
inputBuffer.put(input);
inputBuffer.position(0);
checkDecoder_decodeByteBuffer(decoder, inputBuffer, expectedBytes);
inputBuffer = ByteBuffer.allocateDirect(input.length);
inputBuffer.put(input);
inputBuffer.position(0);
checkDecoder_decodeByteBuffer(decoder, inputBuffer, expectedBytes);
}
use of java.util.Base64.Decoder in project j2objc by google.
the class Base64Test method testRoundtrip_wrap_basic.
public void testRoundtrip_wrap_basic() throws Exception {
Encoder encoder = Base64.getEncoder();
Decoder decoder = Base64.getDecoder();
checkRoundTrip_wrapInputStream(encoder, decoder);
}
Aggregations