Skip to content

Commit 49c286e

Browse files
committed
update Java version
1 parent 98ad931 commit 49c286e

19 files changed

+623
-230
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ project, add the following to the `dependencies` section in your `pom.xml` file:
2525
<dependency>
2626
<groupId>com.upokecenter</groupId>
2727
<artifactId>cbor</artifactId>
28-
<version>2.3.0</version>
28+
<version>2.4.0</version>
2929
</dependency>
3030
```
3131

@@ -90,7 +90,7 @@ Source code is available in the [project page](https://github.com/peteroupc/CBOR
9090
About
9191
-----------
9292

93-
Written in 2013-2014 by Peter O.
93+
Written in 2013-2016 by Peter O.
9494

9595
Any copyright is dedicated to the Public Domain.
9696
[http://creativecommons.org/publicdomain/zero/1.0/](http://creativecommons.org/publicdomain/zero/1.0/)

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>com.upokecenter</groupId>
55
<artifactId>cbor</artifactId>
66
<packaging>jar</packaging>
7-
<version>2.3.1</version>
7+
<version>2.4.0</version>
88
<name>CBOR</name>
99
<description>
1010
A Java implementation of Concise Binary Object Representation (CBOR), a general-purpose binary data format defined in RFC 7049. According to that RFC, CBOR's data model "is an extended version of the JSON data model", supporting many more types of data than JSON. This implementation was written by Peter O. and is released to the Public Domain under the CC0 Declaration.

src/main/java/com/upokecenter/cbor/CBORInteger.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public boolean IsNegative(Object obj) {
114114
public boolean IsNegativeInfinity(Object obj) {
115115
return false;
116116
}
117+
117118
public boolean IsPositiveInfinity(Object obj) {
118119
return false;
119120
}

src/main/java/com/upokecenter/cbor/CBORJson.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ static void WriteJSONToInternal(
576576
return;
577577
}
578578
if (flo.isFinite() &&
579-
(flo.getExponent()).Abs().compareTo(EInteger.FromInt64(2500)) > 0) {
579+
flo.getExponent().Abs().compareTo(EInteger.FromInt64(2500)) > 0) {
580580
// Too inefficient to convert to a decimal number
581581
// from a bigfloat with a very high exponent,
582582
// so convert to double instead

src/main/java/com/upokecenter/cbor/CBORObject.java

Lines changed: 55 additions & 50 deletions
Large diffs are not rendered by default.

src/main/java/com/upokecenter/cbor/CBORObjectMath.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public static CBORObject Divide(CBORObject a, CBORObject b) {
312312
EInteger bigrem;
313313
EInteger bigquo;
314314
{
315-
EInteger[] divrem = (b1).DivRem(b2);
315+
EInteger[] divrem = b1.DivRem(b2);
316316
bigquo = divrem[0];
317317
bigrem = divrem[1]; }
318318
return bigrem.isZero() ? CBORObject.FromObject(bigquo) :

src/main/java/com/upokecenter/cbor/CBORReader.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class CBORReader {
1919
private CBORDuplicatePolicy policy;
2020
private StringRefs stringRefs;
2121

22-
public CBORReader(InputStream stream) {
23-
this.stream = stream;
22+
public CBORReader(InputStream inStream) {
23+
this.stream = inStream;
2424
this.sharedRefs = new SharedRefs();
2525
this.policy = CBORDuplicatePolicy.Overwrite;
2626
}
@@ -244,6 +244,11 @@ public CBORObject ReadForFirstByte(
244244
" is bigger than supported");
245245
}
246246
if (nextByte != 0x60) { // NOTE: 0x60 means the empty String
247+
if (PropertyMap.ExceedsKnownLength(this.stream, len)) {
248+
// TODO: Remove following line in version 3.0
249+
PropertyMap.SkipStreamToEnd(this.stream);
250+
throw new CBORException("Premature end of data");
251+
}
247252
switch (
248253
DataUtilities.ReadUtf8(
249254
this.stream,
@@ -270,6 +275,11 @@ public CBORObject ReadForFirstByte(
270275
CBORUtilities.LongToString(uadditional) +
271276
" is bigger than supported");
272277
}
278+
if (PropertyMap.ExceedsKnownLength(this.stream, uadditional)) {
279+
// TODO: Remove following line in version 3.0
280+
PropertyMap.SkipStreamToEnd(this.stream);
281+
throw new CBORException("Premature end of data");
282+
}
273283
StringBuilder builder = new StringBuilder();
274284
switch (
275285
DataUtilities.ReadUtf8(
@@ -336,6 +346,11 @@ public CBORObject ReadForFirstByte(
336346
if (filter != null && !filter.ArrayLengthMatches(uadditional)) {
337347
throw new CBORException("Array is too long");
338348
}
349+
if (PropertyMap.ExceedsKnownLength(this.stream, uadditional)) {
350+
// TODO: Remove following line in version 3.0
351+
PropertyMap.SkipStreamToEnd(this.stream);
352+
throw new CBORException("Remaining data too small for array length");
353+
}
339354
++this.depth;
340355
for (long i = 0; i < uadditional; ++i) {
341356
cbor.Add(
@@ -383,6 +398,11 @@ public CBORObject ReadForFirstByte(
383398
CBORUtilities.LongToString(uadditional) +
384399
" is bigger than supported");
385400
}
401+
if (PropertyMap.ExceedsKnownLength(this.stream, uadditional)) {
402+
// TODO: Remove following line in version 3.0
403+
PropertyMap.SkipStreamToEnd(this.stream);
404+
throw new CBORException("Remaining data too small for map length");
405+
}
386406
for (long i = 0; i < uadditional; ++i) {
387407
++this.depth;
388408
CBORObject key = this.Read(null);
@@ -508,6 +528,11 @@ private static byte[] ReadByteData(
508528
throw new CBORException("Length" + ToUnsignedBigInteger(uadditional) +
509529
" is bigger than supported ");
510530
}
531+
if (PropertyMap.ExceedsKnownLength(stream, uadditional)) {
532+
// TODO: Remove following line in version 3.0
533+
PropertyMap.SkipStreamToEnd(stream);
534+
throw new CBORException("Premature end of stream");
535+
}
511536
if (uadditional <= 0x10000) {
512537
// Simple case: small size
513538
byte[] data = new byte[(int)uadditional];
@@ -535,7 +560,7 @@ private static byte[] ReadByteData(
535560
}
536561
java.io.ByteArrayOutputStream ms = null;
537562
try {
538-
ms = new java.io.ByteArrayOutputStream();
563+
ms = new java.io.ByteArrayOutputStream(0x10000);
539564

540565
while (total > 0) {
541566
int bufsize = Math.min(tmpdata.length, total);

src/main/java/com/upokecenter/cbor/CBORTypeFilter.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public final class CBORTypeFilter {
5050
*/
5151
public static final CBORTypeFilter UnsignedInteger = new
5252
CBORTypeFilter().WithUnsignedInteger();
53+
5354
private boolean any;
5455
private boolean anyArrayLength;
5556
private int arrayLength;
@@ -64,10 +65,11 @@ public final class CBORTypeFilter {
6465
* index is allowed under this type filter.
6566
* @param index An array index, starting from 0.
6667
* @return true if this type filter allows CBOR arrays and the given array
67-
* index is allowed under this type filter, otherwise, false.
68+
* index is allowed under this type filter; otherwise, false.
6869
*/
6970
public boolean ArrayIndexAllowed(int index) {
70-
return (this.types & (1 << 4)) != 0 && index >= 0 && (this.anyArrayLength||
71+
return (this.types & (1 << 4)) != 0 && index >= 0 &&
72+
(this.anyArrayLength ||
7173
((this.arrayMinLength || index < this.arrayLength) && index >=
7274
0));
7375
}

src/main/java/com/upokecenter/cbor/PropertyMap.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
at: http://peteroupc.github.io/CBOR/
88
*/
99

10+
import java.io.InputStream;
1011
import java.lang.reflect.InvocationTargetException;
1112
import java.lang.reflect.Method;
1213
import java.lang.reflect.Array;
@@ -171,6 +172,13 @@ private static Method getLegacyMethod(int method){
171172
}
172173
}
173174

175+
public static boolean ExceedsKnownLength(InputStream inStream, long size) {
176+
return false;
177+
}
178+
179+
public static void SkipStreamToEnd(InputStream inStream) {
180+
}
181+
174182
public static BigInteger ToLegacy(EInteger ei){
175183
return (BigInteger)InvokeOneArgumentMethod(
176184
getLegacyMethod(0), null, ei);

src/main/java/com/upokecenter/util/BigInteger.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ public final class BigInteger implements Comparable<BigInteger> {
4141
@Deprecated
4242
public static final BigInteger ONE = new BigInteger(EInteger.FromInt32(1));
4343

44-
private static final BigInteger oneValue = new BigInteger(EInteger.FromInt32(1));
44+
private static final BigInteger ValueOneValue = new
45+
BigInteger(EInteger.FromInt32(1));
46+
4547
private final EInteger ei;
4648

4749
BigInteger(EInteger ei) {
@@ -54,6 +56,7 @@ public final class BigInteger implements Comparable<BigInteger> {
5456
static BigInteger ToLegacy(EInteger ei) {
5557
return new BigInteger(ei);
5658
}
59+
5760
static EInteger FromLegacy(BigInteger bei) {
5861
return bei.getEi();
5962
}
@@ -73,12 +76,12 @@ static EInteger FromLegacy(BigInteger bei) {
7376
public static final BigInteger ZERO = new
7477
BigInteger(EInteger.FromInt32(0));
7578

76-
private static final BigInteger zeroValue = new
79+
private static final BigInteger ValueZeroValue = new
7780
BigInteger(EInteger.FromInt32(0));
7881

7982
/**
8083
* Gets a value indicating whether this value is even.
81-
* @return True if this value is even; otherwise, false.
84+
* @return true if this value is even; otherwise, false.
8285
* @deprecated Use EInteger from PeterO.Numbers/com.upokecenter.numbers.
8386
*/
8487
@Deprecated
@@ -88,7 +91,7 @@ public final boolean isEven() {
8891

8992
/**
9093
* Gets a value indicating whether this value is 0.
91-
* @return True if this value is 0; otherwise, false.
94+
* @return true if this value is 0; otherwise, false.
9295
* @deprecated Use EInteger from PeterO.Numbers/com.upokecenter.numbers.
9396
*/
9497
@Deprecated
@@ -300,7 +303,7 @@ public int bitLength() {
300303

301304
/**
302305
* Returns whether this object's value can fit in a 32-bit signed integer.
303-
* @return True if this object's value is MinValue or greater, and MaxValue or
306+
* @return true if this object's value is MinValue or greater, and MaxValue or
304307
* less; otherwise, false.
305308
* @deprecated Use EInteger from PeterO.Numbers/com.upokecenter.numbers.
306309
*/
@@ -367,7 +370,7 @@ public BigInteger[] divideAndRemainder(BigInteger divisor) {
367370
/**
368371
* Determines whether this object and another object are equal.
369372
* @param obj An arbitrary object.
370-
* @return True if this object and another object are equal; otherwise, false.
373+
* @return true if this object and another object are equal; otherwise, false.
371374
*/
372375
@Override public boolean equals(Object obj) {
373376
BigInteger bi = ((obj instanceof BigInteger) ? (BigInteger)obj : null);
@@ -419,7 +422,7 @@ public int getDigitCount() {
419422
*/
420423
@Deprecated
421424
public int getLowBit() {
422-
return (this.isZero()) ? (0) : (this.getEi().GetLowBit());
425+
return this.isZero() ? 0 : this.getEi().GetLowBit();
423426
}
424427

425428
/**
@@ -713,7 +716,7 @@ public BigInteger subtract(BigInteger subtrahend) {
713716
* object's value.
714717
* @param index Zero based index of the bit to test. 0 means the least
715718
* significant bit.
716-
* @return True if a bit is set in the two's-complement representation of this
719+
* @return true if a bit is set in the two's-complement representation of this
717720
* object's value; otherwise, false.
718721
* @deprecated Use EInteger from PeterO.Numbers/com.upokecenter.numbers.
719722
*/

0 commit comments

Comments
 (0)