Unterschied zwischen String.getBytes() und IOUtils.toByteArray()?

Teste ich die IOUtils. Ich habe Probleme bei der Umwandlung eines InputStream in ein byte-array:

private static final String LOREM_IPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";

@Test
public void testInputStreamToByteArray() throws IOException {

    byte[] expecteds = LOREM_IPSUM.getBytes();
    byte[] actuals = org.apache.commons.io.IOUtils.toByteArray(new StringInputStream(LOREM_IPSUM));

    assertArrayEquals(expecteds, actuals);
}

Stacktrace:

java.lang.AssertionError: array lengths differed, expected.length=56 actual.length=112
    at org.junit.Assert.fail(Assert.java:91)
    at org.junit.internal.ComparisonCriteria.assertArraysAreSameLength(ComparisonCriteria.java:72)
    at org.junit.internal.ComparisonCriteria.arrayEquals(ComparisonCriteria.java:36)
    at org.junit.Assert.internalArrayEquals(Assert.java:414)
    at org.junit.Assert.assertArrayEquals(Assert.java:200)
    at org.junit.Assert.assertArrayEquals(Assert.java:213)
    at [...].testInputStreamToByteArray(HttpsTest.java:20)[...]

Ich sehe nicht ein, warum die Prüfung nicht bestanden. Was ist falsch?

InformationsquelleAutor Falci | 2012-11-23
Schreibe einen Kommentar