public void testToBytesBinaryTrailingBackslashes() throws Exception { try { Bytes.toBytesBinary("abc\\x00\\x01\\"); } catch (StringIndexOutOfBoundsException ex) { fail("Illegal string access: " + ex.getMessage()); } }
private void verifyReversibleForBytes(byte[] originalBytes) { String convertedString = Bytes.toStringBinary(originalBytes); byte[] convertedBytes = Bytes.toBytesBinary(convertedString); if (Bytes.compareTo(originalBytes, convertedBytes) != 0) { fail("Not reversible for\nbyte[]: " + Arrays.toString(originalBytes) + ",\nStringBinary: " + convertedString); } }
public void testFixedSizeString() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); Bytes.writeStringFixedSize(dos, "Hello", 5); Bytes.writeStringFixedSize(dos, "World", 18); Bytes.writeStringFixedSize(dos, "", 9); try { // Use a long dash which is three bytes in UTF-8. If encoding happens // using ISO-8859-1, this will fail. Bytes.writeStringFixedSize(dos, "Too\u2013Long", 9); fail("Exception expected"); } catch (IOException ex) { assertEquals( "Trying to write 10 bytes (Too\\xE2\\x80\\x93Long) into a field of " + "length 9", ex.getMessage()); } ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); DataInputStream dis = new DataInputStream(bais); assertEquals("Hello", Bytes.readStringFixedSize(dis, 5)); assertEquals("World", Bytes.readStringFixedSize(dis, 18)); assertEquals("", Bytes.readStringFixedSize(dis, 9)); }
public void testToBytesBinaryTrailingBackslashes() throws Exception { try { Bytes.toBytesBinary("abc\\x00\\x01\\"); } catch (StringIndexOutOfBoundsException ex) { fail("Illegal string access: " + ex.getMessage()); } }
public void testToBytesBinaryTrailingBackslashes() throws Exception { try { Bytes.toBytesBinary("abc\\x00\\x01\\"); } catch (StringIndexOutOfBoundsException ex) { fail("Illegal string access: " + ex.getMessage()); } }
private void verifyReversibleForBytes(byte[] originalBytes) { String convertedString = Bytes.toStringBinary(originalBytes); byte[] convertedBytes = Bytes.toBytesBinary(convertedString); if (Bytes.compareTo(originalBytes, convertedBytes) != 0) { fail("Not reversible for\nbyte[]: " + Arrays.toString(originalBytes) + ",\nStringBinary: " + convertedString); } }
private void verifyReversibleForBytes(byte[] originalBytes) { String convertedString = Bytes.toStringBinary(originalBytes); byte[] convertedBytes = Bytes.toBytesBinary(convertedString); if (Bytes.compareTo(originalBytes, convertedBytes) != 0) { fail("Not reversible for\nbyte[]: " + Arrays.toString(originalBytes) + ",\nStringBinary: " + convertedString); } }
public void testFixedSizeString() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); Bytes.writeStringFixedSize(dos, "Hello", 5); Bytes.writeStringFixedSize(dos, "World", 18); Bytes.writeStringFixedSize(dos, "", 9); try { // Use a long dash which is three bytes in UTF-8. If encoding happens // using ISO-8859-1, this will fail. Bytes.writeStringFixedSize(dos, "Too\u2013Long", 9); fail("Exception expected"); } catch (IOException ex) { assertEquals( "Trying to write 10 bytes (Too\\xE2\\x80\\x93Long) into a field of " + "length 9", ex.getMessage()); } ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); DataInputStream dis = new DataInputStream(bais); assertEquals("Hello", Bytes.readStringFixedSize(dis, 5)); assertEquals("World", Bytes.readStringFixedSize(dis, 18)); assertEquals("", Bytes.readStringFixedSize(dis, 9)); }
public void testFixedSizeString() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); Bytes.writeStringFixedSize(dos, "Hello", 5); Bytes.writeStringFixedSize(dos, "World", 18); Bytes.writeStringFixedSize(dos, "", 9); try { // Use a long dash which is three bytes in UTF-8. If encoding happens // using ISO-8859-1, this will fail. Bytes.writeStringFixedSize(dos, "Too\u2013Long", 9); fail("Exception expected"); } catch (IOException ex) { assertEquals( "Trying to write 10 bytes (Too\\xE2\\x80\\x93Long) into a field of " + "length 9", ex.getMessage()); } ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); DataInputStream dis = new DataInputStream(bais); assertEquals("Hello", Bytes.readStringFixedSize(dis, 5)); assertEquals("World", Bytes.readStringFixedSize(dis, 18)); assertEquals("", Bytes.readStringFixedSize(dis, 9)); }