You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
in Java for the Java version) shows how to use a subclassed
4918
4918
<code>OutputStream</code> together with a <code>ByteArrayOutputStream</code> to
4919
4919
limit the size of supported JSON serializations of CBOR objects.</p>
4920
-
<pre> /* maximum supported JSON size in bytes*/ final int maxSize = 20000; ByteArrayOutputStream ba = new ByteArrayOutputStream(); /* throws UnsupportedOperationException if too big*/ cborObject.WriteJSONTo(new FilterOutputStream(ba) { private int size = 0; public void write(byte[] b, int off, int len) { if (len>(maxSize-size)) { throw new UnsupportedOperationException(); } size+=len; out.write(b, off, len); } public void write(byte b) { if (size >= maxSize) { throw new UnsupportedOperationException(); } size++; out.write(b); } }); byte[] bytes = ba.toByteArray(); </pre> <p>The
4921
-
following example (originally written in C# for the.NET version)
4922
-
shows how to use a.NET MemoryStream to limit the size of supported
4923
-
JSON serializations of CBOR objects. The disadvantage is that the
4924
-
extra memory needed to do so can be wasteful, especially if the
4925
-
average serialized object is much smaller than the maximum size
4920
+
<pre> /* maximum supported JSON size in bytes*/ final int maxSize = 20000; ByteArrayOutputStream ba = new ByteArrayOutputStream(); /* throws UnsupportedOperationException if too big*/ cborObject.WriteJSONTo(new FilterOutputStream(ba) { private int size = 0; public void write(byte[] b, int off, int len) { if (len>(maxSize-size)) { throw new UnsupportedOperationException(); } size+=len; out.write(b, off, len); } public void write(byte b) { if (size >= maxSize) { throw new UnsupportedOperationException(); } size++; out.write(b); } }); byte[] bytes = ba.toByteArray(); </pre>
4921
+
<p>The following example (originally written in C# for the.NET
4922
+
version) shows how to use a.NET MemoryStream to limit the size of
4923
+
supported JSON serializations of CBOR objects. The disadvantage is
4924
+
that the extra memory needed to do so can be wasteful, especially if
4925
+
the average serialized object is much smaller than the maximum size
4926
4926
given (for example, if the maximum size is 20000 bytes, but the
4927
4927
average serialized object has a size of 50 bytes).</p> <pre> byte[] backing = new byte[20000]; /* maximum supported JSON size in bytes*/ byte[] bytes1, bytes2; {
} </pre> <p>The following example (written in Java for
5314
5314
the Java version) shows how to use a subclassed <code>OutputStream</code>
5315
5315
together with a <code>ByteArrayOutputStream</code> to limit the size of
5316
-
supported CBOR serializations.</p> <pre> /* maximum supported CBOR size in bytes*/ final int maxSize = 20000; ByteArrayOutputStream ba = new ByteArrayOutputStream(); /* throws UnsupportedOperationException if too big*/ cborObject.WriteTo(new FilterOutputStream(ba) { private int size = 0; public void write(byte[] b, int off, int len) { if (len>(maxSize-size)) { throw new UnsupportedOperationException(); } size+=len; out.write(b, off, len); } public void write(byte b) { if (size >= maxSize) { throw new UnsupportedOperationException(); } size++; out.write(b); } }); byte[] bytes = ba.toByteArray(); </pre> <p>The
5317
-
following example (originally written in C# for the.NET version)
5318
-
shows how to use a.NET MemoryStream to limit the size of supported
5319
-
CBOR serializations. The disadvantage is that the extra memory
5320
-
needed to do so can be wasteful, especially if the average
5316
+
supported CBOR serializations.</p> <pre> /* maximum supported CBOR size in bytes*/ final int maxSize = 20000; ByteArrayOutputStream ba = new ByteArrayOutputStream(); /* throws UnsupportedOperationException if too big*/ cborObject.WriteTo(new FilterOutputStream(ba) { private int size = 0; public void write(byte[] b, int off, int len) { if (len>(maxSize-size)) { throw new UnsupportedOperationException(); } size+=len; out.write(b, off, len); } public void write(byte b) { if (size >= maxSize) { throw new UnsupportedOperationException(); } size++; out.write(b); } }); byte[] bytes = ba.toByteArray(); </pre>
5317
+
<p>The following example (originally written in C# for the.NET
5318
+
version) shows how to use a.NET MemoryStream to limit the size of
5319
+
supported CBOR serializations. The disadvantage is that the extra
5320
+
memory needed to do so can be wasteful, especially if the average
5321
5321
serialized object is much smaller than the maximum size given (for
5322
5322
example, if the maximum size is 20000 bytes, but the average
5323
5323
serialized object has a size of 50 bytes).</p> <pre> byte[] backing = new byte[20000]; /* maximum supported CBOR size in bytes*/ byte[] bytes1, bytes2; {
<description>A Java implementation of Concise Binary Object Representation (CBOR), a general-purpose binary data format defined in RFC 8949.</description>
Copy file name to clipboardexpand all lines: src/main/java/com/upokecenter/cbor/CBORObject.java
+11-12
Original file line number
Diff line number
Diff line change
@@ -1904,7 +1904,6 @@ public long CalcEncodedSize() {
1904
1904
returnthis.CalcEncodedSize(0);
1905
1905
}
1906
1906
1907
-
// TODO: Use CBOREncodeOptions in CalcEncodedSize
1908
1907
privatelongCalcEncodedSize(intdepth) {
1909
1908
if (depth > 1000) {
1910
1909
thrownewCBORException("Too deeply nested");
@@ -5902,12 +5901,12 @@ public CBORObject UntagOne() {
5902
5901
* in Java for the Java version) shows how to use a subclassed
5903
5902
* <code>OutputStream</code> together with a <code>ByteArrayOutputStream</code> to
5904
5903
* limit the size of supported JSON serializations of CBOR objects.</p>
5905
-
* <pre> /* maximum supported JSON size in bytes*/ final int maxSize = 20000; ByteArrayOutputStream ba = new ByteArrayOutputStream(); /* throws UnsupportedOperationException if too big*/ cborObject.WriteJSONTo(new FilterOutputStream(ba) { private int size = 0; public void write(byte[] b, int off, int len) { if (len>(maxSize-size)) { throw new UnsupportedOperationException(); } size+=len; out.write(b, off, len); } public void write(byte b) { if (size >= maxSize) { throw new UnsupportedOperationException(); } size++; out.write(b); } }); byte[] bytes = ba.toByteArray(); </pre> <p>The
5906
-
* following example (originally written in C# for the.NET version)
5907
-
* shows how to use a.NET MemoryStream to limit the size of supported
5908
-
* JSON serializations of CBOR objects. The disadvantage is that the
5909
-
* extra memory needed to do so can be wasteful, especially if the
5910
-
* average serialized object is much smaller than the maximum size
5904
+
* <pre> /* maximum supported JSON size in bytes*/ final int maxSize = 20000; ByteArrayOutputStream ba = new ByteArrayOutputStream(); /* throws UnsupportedOperationException if too big*/ cborObject.WriteJSONTo(new FilterOutputStream(ba) { private int size = 0; public void write(byte[] b, int off, int len) { if (len>(maxSize-size)) { throw new UnsupportedOperationException(); } size+=len; out.write(b, off, len); } public void write(byte b) { if (size >= maxSize) { throw new UnsupportedOperationException(); } size++; out.write(b); } }); byte[] bytes = ba.toByteArray(); </pre>
5905
+
* <p>The following example (originally written in C# for the.NET
5906
+
* version) shows how to use a.NET MemoryStream to limit the size of
5907
+
* supported JSON serializations of CBOR objects. The disadvantage is
5908
+
* that the extra memory needed to do so can be wasteful, especially if
5909
+
* the average serialized object is much smaller than the maximum size
5911
5910
* given (for example, if the maximum size is 20000 bytes, but the
5912
5911
* average serialized object has a size of 50 bytes).</p> <pre> byte[] backing = new byte[20000]; /* maximum supported JSON size in bytes*/ byte[] bytes1, bytes2; {
5913
5912
java.io.ByteArrayOutputStream ms = null;
@@ -6466,11 +6465,11 @@ public static int WriteValue(
6466
6465
} </pre> <p>The following example (written in Java for
6467
6466
* the Java version) shows how to use a subclassed <code>OutputStream</code>
6468
6467
* together with a <code>ByteArrayOutputStream</code> to limit the size of
6469
-
* supported CBOR serializations.</p> <pre> /* maximum supported CBOR size in bytes*/ final int maxSize = 20000; ByteArrayOutputStream ba = new ByteArrayOutputStream(); /* throws UnsupportedOperationException if too big*/ cborObject.WriteTo(new FilterOutputStream(ba) { private int size = 0; public void write(byte[] b, int off, int len) { if (len>(maxSize-size)) { throw new UnsupportedOperationException(); } size+=len; out.write(b, off, len); } public void write(byte b) { if (size >= maxSize) { throw new UnsupportedOperationException(); } size++; out.write(b); } }); byte[] bytes = ba.toByteArray(); </pre> <p>The
6470
-
* following example (originally written in C# for the.NET version)
6471
-
* shows how to use a.NET MemoryStream to limit the size of supported
6472
-
* CBOR serializations. The disadvantage is that the extra memory
6473
-
* needed to do so can be wasteful, especially if the average
6468
+
* supported CBOR serializations.</p> <pre> /* maximum supported CBOR size in bytes*/ final int maxSize = 20000; ByteArrayOutputStream ba = new ByteArrayOutputStream(); /* throws UnsupportedOperationException if too big*/ cborObject.WriteTo(new FilterOutputStream(ba) { private int size = 0; public void write(byte[] b, int off, int len) { if (len>(maxSize-size)) { throw new UnsupportedOperationException(); } size+=len; out.write(b, off, len); } public void write(byte b) { if (size >= maxSize) { throw new UnsupportedOperationException(); } size++; out.write(b); } }); byte[] bytes = ba.toByteArray(); </pre>
6469
+
* <p>The following example (originally written in C# for the.NET
6470
+
* version) shows how to use a.NET MemoryStream to limit the size of
6471
+
* supported CBOR serializations. The disadvantage is that the extra
6472
+
* memory needed to do so can be wasteful, especially if the average
6474
6473
* serialized object is much smaller than the maximum size given (for
6475
6474
* example, if the maximum size is 20000 bytes, but the average
6476
6475
* serialized object has a size of 50 bytes).</p> <pre> byte[] backing = new byte[20000]; /* maximum supported CBOR size in bytes*/ byte[] bytes1, bytes2; {
0 commit comments