Skip to content

Commit 342f709

Browse files
committed
ByteArrayOrigin should be able convert a byte[] to a
ByteArrayInputStream.
1 parent fb78f68 commit 342f709

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/changes/changes.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,14 @@ The <action> type attribute can be add,update,fix,remove.
5252
<action issue="IO-791" dev="ggregory" type="fix" due-to="Chad Wilson, Gary Gregory">
5353
Regression in FileUtils.touch() - no longer creates parent directories.
5454
</action>
55-
<!-- ADD -->
5655
<action dev="ggregory" type="fix" due-to="Gary Gregory">
56+
ByteArrayOrigin should be able convert a byte[] to a ByteArrayInputStream.
57+
</action>
58+
<!-- ADD -->
59+
<action dev="ggregory" type="add" due-to="Gary Gregory">
5760
Add CharSequenceInputStream.Builder.
5861
</action>
59-
<action dev="ggregory" type="fix" due-to="Gary Gregory">
62+
<action dev="ggregory" type="add" due-to="Gary Gregory">
6063
Add AbstractStreamBuilder.setOpenOptions(OpenOption...).
6164
</action>
6265
<!-- UPDATE -->

src/main/java/org/apache/commons/io/build/AbstractOrigin.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.apache.commons.io.build;
1919

20+
import java.io.ByteArrayInputStream;
2021
import java.io.File;
2122
import java.io.IOException;
2223
import java.io.InputStream;
@@ -65,6 +66,11 @@ public byte[] getByteArray() {
6566
return get();
6667
}
6768

69+
@Override
70+
public InputStream getInputStream(final OpenOption... options) throws IOException {
71+
return new ByteArrayInputStream(getByteArray());
72+
}
73+
6874
}
6975

7076
/**

src/test/java/org/apache/commons/io/input/MessageDigestCalculatingInputStreamTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ public void test() throws Exception {
5151
messageDigestInputStream.consume();
5252
assertArrayEquals(expect, messageDigestInputStream.getMessageDigest().digest());
5353
}
54+
try (MessageDigestCalculatingInputStream messageDigestInputStream = MessageDigestCalculatingInputStream.builder().setByteArray(buffer).get()) {
55+
messageDigestInputStream.consume();
56+
assertArrayEquals(expect, messageDigestInputStream.getMessageDigest().digest());
57+
}
5458
}
5559
}
5660

0 commit comments

Comments
 (0)