From ef582716ecf1abb22469c7c1b3a308ca927821b9 Mon Sep 17 00:00:00 2001 From: Jaeyun Jung Date: Sun, 22 Sep 2019 16:00:54 +0900 Subject: [PATCH] [Android/Api] update condition 1. update condition to check the given params. 2. update api description about ml model. Signed-off-by: Jaeyun Jung --- .../api/src/main/java/org/nnsuite/nnstreamer/NNStreamer.java | 3 +++ .../api/src/main/java/org/nnsuite/nnstreamer/SingleShot.java | 4 ++-- .../api/src/main/java/org/nnsuite/nnstreamer/TensorsData.java | 8 ++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/api/android/api/src/main/java/org/nnsuite/nnstreamer/NNStreamer.java b/api/android/api/src/main/java/org/nnsuite/nnstreamer/NNStreamer.java index f974d45..5de8c4d 100644 --- a/api/android/api/src/main/java/org/nnsuite/nnstreamer/NNStreamer.java +++ b/api/android/api/src/main/java/org/nnsuite/nnstreamer/NNStreamer.java @@ -26,6 +26,9 @@ import org.freedesktop.gstreamer.GStreamer; * NNStreamer is a set of GStreamer plugins that allow GStreamer developers to adopt neural network models easily and efficiently * and neural network developers to manage stream pipelines and their filters easily and efficiently.
*
+ * Note that, to open a machine learning model in the storage, + * the permission Manifest.permission.READ_EXTERNAL_STORAGE is required before constructing the pipeline. + *
* See https://github.com/nnsuite/nnstreamer for the details. */ public final class NNStreamer { diff --git a/api/android/api/src/main/java/org/nnsuite/nnstreamer/SingleShot.java b/api/android/api/src/main/java/org/nnsuite/nnstreamer/SingleShot.java index 19521f2..a4575ce 100644 --- a/api/android/api/src/main/java/org/nnsuite/nnstreamer/SingleShot.java +++ b/api/android/api/src/main/java/org/nnsuite/nnstreamer/SingleShot.java @@ -69,8 +69,8 @@ public final class SingleShot implements AutoCloseable { * @throws IllegalStateException if failed to construct the pipeline */ public SingleShot(@NonNull File model, @Nullable TensorsInfo in, @Nullable TensorsInfo out) { - if (model == null) { - throw new IllegalArgumentException("The param model is null"); + if (model == null || !model.exists()) { + throw new IllegalArgumentException("The param model is invalid"); } String path = model.getAbsolutePath(); diff --git a/api/android/api/src/main/java/org/nnsuite/nnstreamer/TensorsData.java b/api/android/api/src/main/java/org/nnsuite/nnstreamer/TensorsData.java index 560c8f8..ea66c63 100644 --- a/api/android/api/src/main/java/org/nnsuite/nnstreamer/TensorsData.java +++ b/api/android/api/src/main/java/org/nnsuite/nnstreamer/TensorsData.java @@ -35,11 +35,11 @@ public final class TensorsData implements AutoCloseable { * @return The new byte buffer */ public static ByteBuffer allocateByteBuffer(int size) { - ByteBuffer buffer = ByteBuffer.allocateDirect(size); - - buffer.order(ByteOrder.nativeOrder()); + if (size <= 0) { + throw new IllegalArgumentException("The param size is invalid"); + } - return buffer; + return ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder()); } /** -- 2.7.4