Skip to content

Commit

Permalink
update Java version
Browse files Browse the repository at this point in the history
  • Loading branch information
peteroupc committed Apr 19, 2021
1 parent 1cb2aae commit 467ddb5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ project, add the following to the `dependencies` section in your `pom.xml` file:
<dependency>
<groupId>com.upokecenter</groupId>
<artifactId>cbor</artifactId>
<version>4.3.0</version>
<version>4.4.0</version>
</dependency>
```

Expand Down
22 changes: 11 additions & 11 deletions api/com.upokecenter.cbor.CBORObject.md
Original file line number Diff line number Diff line change
Expand Up @@ -4917,12 +4917,12 @@ try { if (ms != null) { ms.close(); } } catch (java.io.IOException ex) {}
in Java for the Java version) shows how to use a subclassed
<code>OutputStream</code> together with a <code>ByteArrayOutputStream</code> to
limit the size of supported JSON serializations of CBOR objects.</p>
<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&gt;(maxSize-size)) { throw new UnsupportedOperationException(); } size+=len; out.write(b, off, len); } public void write(byte b) { if (size &gt;= maxSize) { throw new UnsupportedOperationException(); } size++; out.write(b); } }); byte[] bytes = ba.toByteArray(); </pre> <p>The
following example (originally written in C# for the.NET version)
shows how to use a.NET MemoryStream to limit the size of supported
JSON serializations of CBOR objects. The disadvantage is that the
extra memory needed to do so can be wasteful, especially if the
average serialized object is much smaller than the maximum size
<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&gt;(maxSize-size)) { throw new UnsupportedOperationException(); } size+=len; out.write(b, off, len); } public void write(byte b) { if (size &gt;= maxSize) { throw new UnsupportedOperationException(); } size++; out.write(b); } }); byte[] bytes = ba.toByteArray(); </pre>
<p>The following example (originally written in C# for the.NET
version) shows how to use a.NET MemoryStream to limit the size of
supported JSON serializations of CBOR objects. The disadvantage is
that the extra memory needed to do so can be wasteful, especially if
the average serialized object is much smaller than the maximum size
given (for example, if the maximum size is 20000 bytes, but the
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; {
java.io.ByteArrayOutputStream ms = null;
Expand Down Expand Up @@ -5313,11 +5313,11 @@ try { if (ms != null) { ms.close(); } } catch (java.io.IOException ex) {}
} </pre> <p>The following example (written in Java for
the Java version) shows how to use a subclassed <code>OutputStream</code>
together with a <code>ByteArrayOutputStream</code> to limit the size of
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&gt;(maxSize-size)) { throw new UnsupportedOperationException(); } size+=len; out.write(b, off, len); } public void write(byte b) { if (size &gt;= maxSize) { throw new UnsupportedOperationException(); } size++; out.write(b); } }); byte[] bytes = ba.toByteArray(); </pre> <p>The
following example (originally written in C# for the.NET version)
shows how to use a.NET MemoryStream to limit the size of supported
CBOR serializations. The disadvantage is that the extra memory
needed to do so can be wasteful, especially if the average
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&gt;(maxSize-size)) { throw new UnsupportedOperationException(); } size+=len; out.write(b, off, len); } public void write(byte b) { if (size &gt;= maxSize) { throw new UnsupportedOperationException(); } size++; out.write(b); } }); byte[] bytes = ba.toByteArray(); </pre>
<p>The following example (originally written in C# for the.NET
version) shows how to use a.NET MemoryStream to limit the size of
supported CBOR serializations. The disadvantage is that the extra
memory needed to do so can be wasteful, especially if the average
serialized object is much smaller than the maximum size given (for
example, if the maximum size is 20000 bytes, but the average
serialized object has a size of 50 bytes).</p> <pre> byte[] backing = new byte[20000]; /* maximum supported CBOR size in bytes*/ byte[] bytes1, bytes2; {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.upokecenter</groupId>
<artifactId>cbor</artifactId>
<packaging>jar</packaging>
<version>4.4.0-SNAPSHOT</version>
<version>4.4.0</version>
<name>CBOR (Concise Binary Object Representation)</name>
<description>A Java implementation of Concise Binary Object Representation (CBOR), a general-purpose binary data format defined in RFC 8949.</description>
<url>https://github.com/peteroupc/CBOR-Java</url>
Expand Down
23 changes: 11 additions & 12 deletions src/main/java/com/upokecenter/cbor/CBORObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -1904,7 +1904,6 @@ public long CalcEncodedSize() {
return this.CalcEncodedSize(0);
}

// TODO: Use CBOREncodeOptions in CalcEncodedSize
private long CalcEncodedSize(int depth) {
if (depth > 1000) {
throw new CBORException("Too deeply nested");
Expand Down Expand Up @@ -5902,12 +5901,12 @@ public CBORObject UntagOne() {
* in Java for the Java version) shows how to use a subclassed
* <code>OutputStream</code> together with a <code>ByteArrayOutputStream</code> to
* limit the size of supported JSON serializations of CBOR objects.</p>
* <pre> &#x2f;&#x2a; maximum supported JSON size in bytes&#x2a;&#x2f; final int maxSize = 20000; ByteArrayOutputStream ba = new ByteArrayOutputStream(); &#x2f;&#x2a; throws UnsupportedOperationException if too big&#x2a;&#x2f; 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
* following example (originally written in C# for the.NET version)
* shows how to use a.NET MemoryStream to limit the size of supported
* JSON serializations of CBOR objects. The disadvantage is that the
* extra memory needed to do so can be wasteful, especially if the
* average serialized object is much smaller than the maximum size
* <pre> &#x2f;&#x2a; maximum supported JSON size in bytes&#x2a;&#x2f; final int maxSize = 20000; ByteArrayOutputStream ba = new ByteArrayOutputStream(); &#x2f;&#x2a; throws UnsupportedOperationException if too big&#x2a;&#x2f; cborObject.WriteJSONTo(new FilterOutputStream(ba) { private int size = 0; public void write(byte[] b, int off, int len) { if (len&gt;(maxSize-size)) { throw new UnsupportedOperationException(); } size+=len; out.write(b, off, len); } public void write(byte b) { if (size &gt;= maxSize) { throw new UnsupportedOperationException(); } size++; out.write(b); } }); byte[] bytes = ba.toByteArray(); </pre>
* <p>The following example (originally written in C# for the.NET
* version) shows how to use a.NET MemoryStream to limit the size of
* supported JSON serializations of CBOR objects. The disadvantage is
* that the extra memory needed to do so can be wasteful, especially if
* the average serialized object is much smaller than the maximum size
* given (for example, if the maximum size is 20000 bytes, but the
* average serialized object has a size of 50 bytes).</p> <pre> byte[] backing = new byte[20000]; &#x2f;&#x2a; maximum supported JSON size in bytes&#x2a;&#x2f; byte[] bytes1, bytes2; {
java.io.ByteArrayOutputStream ms = null;
Expand Down Expand Up @@ -6466,11 +6465,11 @@ public static int WriteValue(
} </pre> <p>The following example (written in Java for
* the Java version) shows how to use a subclassed <code>OutputStream</code>
* together with a <code>ByteArrayOutputStream</code> to limit the size of
* supported CBOR serializations.</p> <pre> &#x2f;&#x2a; maximum supported CBOR size in bytes&#x2a;&#x2f; final int maxSize = 20000; ByteArrayOutputStream ba = new ByteArrayOutputStream(); &#x2f;&#x2a; throws UnsupportedOperationException if too big&#x2a;&#x2f; 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
* following example (originally written in C# for the.NET version)
* shows how to use a.NET MemoryStream to limit the size of supported
* CBOR serializations. The disadvantage is that the extra memory
* needed to do so can be wasteful, especially if the average
* supported CBOR serializations.</p> <pre> &#x2f;&#x2a; maximum supported CBOR size in bytes&#x2a;&#x2f; final int maxSize = 20000; ByteArrayOutputStream ba = new ByteArrayOutputStream(); &#x2f;&#x2a; throws UnsupportedOperationException if too big&#x2a;&#x2f; cborObject.WriteTo(new FilterOutputStream(ba) { private int size = 0; public void write(byte[] b, int off, int len) { if (len&gt;(maxSize-size)) { throw new UnsupportedOperationException(); } size+=len; out.write(b, off, len); } public void write(byte b) { if (size &gt;= maxSize) { throw new UnsupportedOperationException(); } size++; out.write(b); } }); byte[] bytes = ba.toByteArray(); </pre>
* <p>The following example (originally written in C# for the.NET
* version) shows how to use a.NET MemoryStream to limit the size of
* supported CBOR serializations. The disadvantage is that the extra
* memory needed to do so can be wasteful, especially if the average
* serialized object is much smaller than the maximum size given (for
* example, if the maximum size is 20000 bytes, but the average
* serialized object has a size of 50 bytes).</p> <pre> byte[] backing = new byte[20000]; &#x2f;&#x2a; maximum supported CBOR size in bytes&#x2a;&#x2f; byte[] bytes1, bytes2; {
Expand Down

0 comments on commit 467ddb5

Please sign in to comment.