File tree Expand file tree Collapse file tree
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/internal/c_api Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -72,7 +72,8 @@ public static TF_Buffer newBufferFromString(Pointer proto) {
7272 }
7373
7474 /**
75- * Returns a copy of the data in a Java array, or throws IndexOutOfBoundsException if too large.
75+ * @return a copy of the data in a Java array
76+ * @throws IndexOutOfBoundsException if too large.
7677 */
7778 public byte [] copyData () {
7879 long length = ((TF_Buffer )this ).length ();
@@ -85,10 +86,15 @@ public byte[] copyData() {
8586 }
8687
8788 /**
88- * Returns the data of this buffer as a {@link java.nio.ByteBuffer}
89+ * @return the data of this buffer as a {@link java.nio.ByteBuffer}
90+ * @throws IndexOutOfBoundsException if too large.
8991 */
9092 public ByteBuffer dataAsByteBuffer () {
91- return ((TF_Buffer )this ).data ().capacity (((TF_Buffer ) this ).length ()).asByteBuffer ();
93+ long length = ((TF_Buffer )this ).length ();
94+ if (length > Integer .MAX_VALUE ) {
95+ throw new IndexOutOfBoundsException ("TF_Buffer is too large to accessed via a ByteBuffer interface" );
96+ }
97+ return ((TF_Buffer )this ).data ().capacity (length ).asByteBuffer ();
9298 }
9399
94100 /**
You can’t perform that action at this time.
0 commit comments