diff --git a/src/main/java/com/dd/plist/ASCIIPropertyListParser.java b/src/main/java/com/dd/plist/ASCIIPropertyListParser.java index 046315d..33026db 100644 --- a/src/main/java/com/dd/plist/ASCIIPropertyListParser.java +++ b/src/main/java/com/dd/plist/ASCIIPropertyListParser.java @@ -568,7 +568,7 @@ private NSArray parseArray() throws ParseException { //parse end token this.read(ARRAY_END_TOKEN); - return new NSArray(objects.toArray(new NSObject[objects.size()])); + return new NSArray(objects.toArray(new NSObject[0])); } /** diff --git a/src/main/java/com/dd/plist/Base64.java b/src/main/java/com/dd/plist/Base64.java index 4cbf9a0..1185797 100644 --- a/src/main/java/com/dd/plist/Base64.java +++ b/src/main/java/com/dd/plist/Base64.java @@ -29,34 +29,34 @@ /** *

Encodes and decodes to and from Base64 notation.

*

Homepage: http://iharder.net/base64.

- * + * *

Example:

* * String encoded = Base64.encode( myByteArray ); * * byte[] myByteArray = Base64.decode( encoded ); - * + * *

The options parameter, which appears in a few places, is used to pass * several pieces of information to the encoder. In the "higher level" methods such as * encodeBytes( bytes, options ) the options parameter can be used to indicate such * things as first gzipping the bytes before encoding them, not inserting linefeeds, * and encoding using the URL-safe and Ordered dialects.

- * + * *

Note, according to RFC3548, * Section 2.1, implementations should not add line feeds unless explicitly told * to do so. I've got Base64 set to this behavior now, although earlier versions * broke lines by default.

- * + * *

The constants defined in Base64 can be OR-ed together to combine options, so you * might make a call like this:

- * + * * String encoded = Base64.encodeBytes( mybytes, Base64.GZIP | Base64.DO_BREAK_LINES ); *

to compress the data before encoding it and then making the output have newline characters.

*

Also...

* String encoded = Base64.encodeBytes( crazyString.getBytes() ); - * - * - * + * + * + * *

* Change Log: *

@@ -133,7 +133,7 @@ * Special thanks to Jim Kellerman at http://www.powerset.com/ * for contributing the new Base64 dialects. * - * + * *
  • v2.1 - Cleaned up javadoc comments and unused variables and methods. Added * some convenience methods for reading and writing to and from files.
  • *
  • v2.0.2 - Now specifies UTF-8 encoding in places where the code fails on systems @@ -641,13 +641,13 @@ public static void encode(java.nio.ByteBuffer raw, java.nio.CharBuffer encoded) /** * Serializes an object and returns the Base64-encoded * version of that serialized object. - * + * *

    As of v 2.3, if the object * cannot be serialized or there is another error, * the method will throw an java.io.IOException. This is new to v2.3! * In earlier versions, it just returned a null value, but * in retrospect that's a pretty poor way to handle it.

    - * + * * The object is not GZip-compressed before being encoded. * * @param serializableObject The object to encode @@ -665,22 +665,22 @@ public static String encodeObject(java.io.Serializable serializableObject) /** * Serializes an object and returns the Base64-encoded * version of that serialized object. - * + * *

    As of v 2.3, if the object * cannot be serialized or there is another error, * the method will throw an java.io.IOException. This is new to v2.3! * In earlier versions, it just returned a null value, but * in retrospect that's a pretty poor way to handle it.

    - * + * * The object is not GZip-compressed before being encoded. - * + * * Example options:
          *   GZIP: gzip-compresses object before encoding it.
          *   DO_BREAK_LINES: break lines at 76 characters
          * 
    - * + * * Example: encodeObject( myObj, Base64.GZIP ) or - * + * * Example: encodeObject( myObj, Base64.GZIP | Base64.DO_BREAK_LINES ) * * @param serializableObject The object to encode @@ -791,8 +791,8 @@ public static String encodeBytes(byte[] source) { * Example: encodeBytes( myData, Base64.GZIP ) or *

    * Example: encodeBytes( myData, Base64.GZIP | Base64.DO_BREAK_LINES ) - * - * + * + * *

    As of v 2.3, if there is an error with the GZIP stream, * the method will throw an java.io.IOException. This is new to v2.3! * In earlier versions, it just returned a null value, but @@ -815,7 +815,7 @@ public static String encodeBytes(byte[] source, int options) throws java.io.IOEx /** * Encodes a byte array into Base64 notation. * Does not GZip-compress data. - * + * *

    As of v 2.3, if there is an error, * the method will throw an java.io.IOException. This is new to v2.3! * In earlier versions, it just returned a null value, but @@ -856,8 +856,8 @@ public static String encodeBytes(byte[] source, int off, int len) { * Example: encodeBytes( myData, Base64.GZIP ) or *

    * Example: encodeBytes( myData, Base64.GZIP | Base64.DO_BREAK_LINES ) - * - * + * + * *

    As of v 2.3, if there is an error with the GZIP stream, * the method will throw an java.io.IOException. This is new to v2.3! * In earlier versions, it just returned a null value, but @@ -1444,7 +1444,7 @@ public Class resolveClass(java.io.ObjectStreamClass streamClass) /** * Convenience method for encoding data to a file. - * + * *

    As of v 2.3, if there is a error, * the method will throw an java.io.IOException. This is new to v2.3! * In earlier versions, it just returned false, but @@ -1484,7 +1484,7 @@ public static void encodeToFile(byte[] dataToEncode, String filename) /** * Convenience method for decoding data to a file. - * + * *

    As of v 2.3, if there is a error, * the method will throw an java.io.IOException. This is new to v2.3! * In earlier versions, it just returned false, but @@ -1520,7 +1520,7 @@ public static void decodeToFile(String dataToDecode, String filename) /** * Convenience method for reading a base64-encoded * file and decoding it. - * + * *

    As of v 2.3, if there is a error, * the method will throw an java.io.IOException. This is new to v2.3! * In earlier versions, it just returned false, but @@ -1581,7 +1581,7 @@ public static byte[] decodeFromFile(String filename) /** * Convenience method for reading a binary file * and base64-encoding it. - * + * *

    As of v 2.3, if there is a error, * the method will throw an java.io.IOException. This is new to v2.3! * In earlier versions, it just returned false, but @@ -1704,15 +1704,15 @@ public static void decodeFileToFile(String infile, String outfile) */ public static class B64InputStream extends java.io.FilterInputStream { - private boolean encode; // Encoding or decoding + private final boolean encode; // Encoding or decoding private int position; // Current position in the buffer - private byte[] buffer; // Small buffer holding converted data - private int bufferLength; // Length of buffer (3 or 4) + private final byte[] buffer; // Small buffer holding converted data + private final int bufferLength; // Length of buffer (3 or 4) private int numSigBytes; // Number of meaningful bytes in the buffer private int lineLength; - private boolean breakLines; // Break lines at less than 80 characters - private int options; // Record options used to create the stream. - private byte[] decodabet; // Local copies to avoid extra method calls + private final boolean breakLines; // Break lines at less than 80 characters + private final int options; // Record options used to create the stream. + private final byte[] decodabet; // Local copies to avoid extra method calls /** @@ -1729,13 +1729,13 @@ public B64InputStream(java.io.InputStream in) { /** * Constructs a {@link com.dd.plist.Base64.B64InputStream} in * either ENCODE or DECODE mode. - * + * * Valid options:

              *   ENCODE or DECODE: Encode or Decode as data is read.
              *   DO_BREAK_LINES: break lines at 76 characters
              *     (only meaningful when encoding)
              * 
    - * + * * Example: new Base64.B64InputStream( in, Base64.DECODE ) * * @param in the java.io.InputStream from which to read data. @@ -1940,13 +1940,13 @@ public B64OutputStream(java.io.OutputStream out) { /** * Constructs a {@link com.dd.plist.Base64.B64OutputStream} in * either ENCODE or DECODE mode. - * + * * Valid options:
              *   ENCODE or DECODE: Encode or Decode as data is read.
              *   DO_BREAK_LINES: don't break lines at 76 characters
              *     (only meaningful when encoding)
              * 
    - * + * * Example: new Base64.B64OutputStream( out, Base64.ENCODE ) * * @param out the java.io.B64OutputStream to which data will be written. diff --git a/src/main/java/com/dd/plist/BinaryPropertyListParser.java b/src/main/java/com/dd/plist/BinaryPropertyListParser.java index bba7ca4..b20e2b6 100644 --- a/src/main/java/com/dd/plist/BinaryPropertyListParser.java +++ b/src/main/java/com/dd/plist/BinaryPropertyListParser.java @@ -84,7 +84,7 @@ public final class BinaryPropertyListParser { private int offsetSize; private int numObjects; private int offsetTableOffset; - private HashMap parsedObjects = new HashMap<>(); + private final HashMap parsedObjects = new HashMap<>(); /** * Protected constructor so that instantiation is fully controlled by the diff --git a/src/main/java/com/dd/plist/NSNull.java b/src/main/java/com/dd/plist/NSNull.java index 7b35002..b96ce8a 100644 --- a/src/main/java/com/dd/plist/NSNull.java +++ b/src/main/java/com/dd/plist/NSNull.java @@ -41,7 +41,7 @@ private NSNull() { * @param o The object. * @return The non-null object, or a NSNull instance. */ - protected static NSObject wrap(NSObject o) { + static NSObject wrap(NSObject o) { return o == null ? NULL : o; } @@ -50,7 +50,7 @@ protected static NSObject wrap(NSObject o) { * @param o The object. * @return The non-null object, or null. */ - protected static NSObject unwrap(NSObject o) { + static NSObject unwrap(NSObject o) { return o == NULL ? null : o; } diff --git a/src/main/java/com/dd/plist/NSObject.java b/src/main/java/com/dd/plist/NSObject.java index 420b704..ac7e9f6 100644 --- a/src/main/java/com/dd/plist/NSObject.java +++ b/src/main/java/com/dd/plist/NSObject.java @@ -22,8 +22,6 @@ */ package com.dd.plist; -import sun.reflect.generics.reflectiveObjects.NotImplementedException; - import java.io.IOException; import java.lang.reflect.*; import java.util.*; @@ -223,8 +221,8 @@ private static boolean isSimple(Class clazz) { private static Object getInstance(Class clazz) { try { - return clazz.newInstance(); - } catch (InstantiationException | IllegalAccessException e) { + return clazz.getDeclaredConstructor().newInstance(); + } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { throw new IllegalArgumentException("Could not instantiate class " + clazz.getSimpleName()); } } @@ -691,7 +689,7 @@ private static NSArray fromCollection(Collection collection) { payload.add(fromJavaObject(elem)); } - return new NSArray(payload.toArray(new NSObject[payload.size()])); + return new NSArray(payload.toArray(new NSObject[0])); } private static NSSet fromSet(Set set) { diff --git a/src/test/java/com/dd/plist/test/model/TestClass1.java b/src/test/java/com/dd/plist/test/model/TestClass1.java index 0b3931f..a11b87c 100644 --- a/src/test/java/com/dd/plist/test/model/TestClass1.java +++ b/src/test/java/com/dd/plist/test/model/TestClass1.java @@ -2,6 +2,7 @@ import java.util.List; import java.util.Map; +import java.util.Objects; public class TestClass1 { @@ -22,7 +23,7 @@ public boolean equals(Object o) { TestClass1 testClass = (TestClass1) o; - return map != null ? map.equals(testClass.map) : testClass.map == null; + return Objects.equals(map, testClass.map); } diff --git a/src/test/java/com/dd/plist/test/model/TestClass2.java b/src/test/java/com/dd/plist/test/model/TestClass2.java index a2d60ff..5aed0a8 100644 --- a/src/test/java/com/dd/plist/test/model/TestClass2.java +++ b/src/test/java/com/dd/plist/test/model/TestClass2.java @@ -1,6 +1,7 @@ package com.dd.plist.test.model; import java.util.Date; +import java.util.Objects; public class TestClass2 { @@ -144,14 +145,14 @@ public boolean equals(Object o) { if (Float.compare(that.aPrimitiveFloat, aPrimitiveFloat) != 0) return false; if (aPrimitiveShort != that.aPrimitiveShort) return false; if (aPrimitiveBoolean != that.aPrimitiveBoolean) return false; - if (aString != null ? !aString.equals(that.aString) : that.aString != null) return false; - if (aInteger != null ? !aInteger.equals(that.aInteger) : that.aInteger != null) return false; - if (aLong != null ? !aLong.equals(that.aLong) : that.aLong != null) return false; - if (aDouble != null ? !aDouble.equals(that.aDouble) : that.aDouble != null) return false; - if (aFloat != null ? !aFloat.equals(that.aFloat) : that.aFloat != null) return false; - if (aShort != null ? !aShort.equals(that.aShort) : that.aShort != null) return false; - if (aBoolean != null ? !aBoolean.equals(that.aBoolean) : that.aBoolean != null) return false; - return aDate != null ? aDate.equals(that.aDate) : that.aDate == null; + if (!Objects.equals(aString, that.aString)) return false; + if (!Objects.equals(aInteger, that.aInteger)) return false; + if (!Objects.equals(aLong, that.aLong)) return false; + if (!Objects.equals(aDouble, that.aDouble)) return false; + if (!Objects.equals(aFloat, that.aFloat)) return false; + if (!Objects.equals(aShort, that.aShort)) return false; + if (!Objects.equals(aBoolean, that.aBoolean)) return false; + return Objects.equals(aDate, that.aDate); } @@ -169,7 +170,7 @@ public int hashCode() { result = 31 * result + (int) (aPrimitiveLong ^ (aPrimitiveLong >>> 32)); temp = Double.doubleToLongBits(aPrimitiveDouble); result = 31 * result + (int) (temp ^ (temp >>> 32)); - result = 31 * result + (aPrimitiveFloat != +0.0f ? Float.floatToIntBits(aPrimitiveFloat) : 0); + result = 31 * result + (aPrimitiveFloat != 0.0f ? Float.floatToIntBits(aPrimitiveFloat) : 0); result = 31 * result + (int) aPrimitiveShort; result = 31 * result + (aBoolean != null ? aBoolean.hashCode() : 0); result = 31 * result + (aPrimitiveBoolean ? 1 : 0);