Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add NDList decode from inputStream #734

Merged
merged 1 commit into from
Mar 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion api/src/main/java/ai/djl/ndarray/NDList.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -77,7 +78,18 @@ public NDList(Collection<NDArray> other) {
* @return {@code NDList}
*/
public static NDList decode(NDManager manager, byte[] byteArray) {
try (DataInputStream dis = new DataInputStream(new ByteArrayInputStream(byteArray))) {
return decode(manager, new ByteArrayInputStream(byteArray));
}

/**
* Decodes NDList from {@link InputStream}.
*
* @param manager manager assigned to {@link NDArray}
* @param is input stream contains the ndlist information
* @return {@code NDList}
*/
public static NDList decode(NDManager manager, InputStream is) {
try (DataInputStream dis = new DataInputStream(is)) {
int size = dis.readInt();
if (size < 0) {
throw new IllegalArgumentException("Invalid NDList size: " + size);
Expand Down