Author: davidb
Date: Thu Oct 27 09:06:52 2016
New Revision: 1766791
URL: http://svn.apache.org/viewvc?rev=1766791&view=rev
Log:
Refactor util class and make private
Added:
felix/trunk/converter/schematizer/src/main/java/org/apache/felix/serializer/impl/json/Util.java
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/Util.java
Modified:
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/Util.java
felix/trunk/converter/schematizer/src/main/java/org/apache/felix/serializer/impl/json/JsonParser.java
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonDeserializingImpl.java
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonParser.java
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlDeserializingImpl.java
Modified:
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/Util.java
URL:
http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/Util.java?rev=1766791&r1=1766790&r2=1766791&view=diff
==============================================================================
---
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/Util.java
(original)
+++
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/Util.java
Thu Oct 27 09:06:52 2016
@@ -16,15 +16,12 @@
*/
package org.apache.felix.converter.impl;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-public class Util {
+class Util {
private static final Map<Class<?>, Class<?>> boxedClasses;
static {
Map<Class<?>, Class<?>> m = new HashMap<>();
@@ -40,6 +37,8 @@ public class Util {
boxedClasses = Collections.unmodifiableMap(m);
}
+ private Util() {} // prevent instantiation
+
static Type primitiveToBoxed(Type type) {
if (type instanceof Class)
return primitiveToBoxed((Class<?>) type);
@@ -54,29 +53,4 @@ public class Util {
else
return cls;
}
-
- public static byte [] readStream(InputStream is) throws IOException {
- try {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- byte[] bytes = new byte[8192];
-
- int length = 0;
- int offset = 0;
-
- while ((length = is.read(bytes, offset, bytes.length - offset)) !=
-1) {
- offset += length;
-
- if (offset == bytes.length) {
- baos.write(bytes, 0, bytes.length);
- offset = 0;
- }
- }
- if (offset != 0) {
- baos.write(bytes, 0, offset);
- }
- return baos.toByteArray();
- } finally {
- is.close();
- }
- }
}
Modified:
felix/trunk/converter/schematizer/src/main/java/org/apache/felix/serializer/impl/json/JsonParser.java
URL:
http://svn.apache.org/viewvc/felix/trunk/converter/schematizer/src/main/java/org/apache/felix/serializer/impl/json/JsonParser.java?rev=1766791&r1=1766790&r2=1766791&view=diff
==============================================================================
---
felix/trunk/converter/schematizer/src/main/java/org/apache/felix/serializer/impl/json/JsonParser.java
(original)
+++
felix/trunk/converter/schematizer/src/main/java/org/apache/felix/serializer/impl/json/JsonParser.java
Thu Oct 27 09:06:52 2016
@@ -26,7 +26,7 @@ import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.apache.felix.converter.impl.Util;
+import org.apache.felix.serializer.impl.Util;
/**
* A very small JSON parser.
Added:
felix/trunk/converter/schematizer/src/main/java/org/apache/felix/serializer/impl/json/Util.java
URL:
http://svn.apache.org/viewvc/felix/trunk/converter/schematizer/src/main/java/org/apache/felix/serializer/impl/json/Util.java?rev=1766791&view=auto
==============================================================================
---
felix/trunk/converter/schematizer/src/main/java/org/apache/felix/serializer/impl/json/Util.java
(added)
+++
felix/trunk/converter/schematizer/src/main/java/org/apache/felix/serializer/impl/json/Util.java
Thu Oct 27 09:06:52 2016
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.felix.serializer.impl.json;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+public class Util {
+ private Util() {} // prevent instantiation
+
+ public static byte [] readStream(InputStream is) throws IOException {
+ try {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ byte[] bytes = new byte[8192];
+
+ int length = 0;
+ int offset = 0;
+
+ while ((length = is.read(bytes, offset, bytes.length - offset)) !=
-1) {
+ offset += length;
+
+ if (offset == bytes.length) {
+ baos.write(bytes, 0, bytes.length);
+ offset = 0;
+ }
+ }
+ if (offset != 0) {
+ baos.write(bytes, 0, offset);
+ }
+ return baos.toByteArray();
+ } finally {
+ is.close();
+ }
+ }
+}
Added:
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/Util.java
URL:
http://svn.apache.org/viewvc/felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/Util.java?rev=1766791&view=auto
==============================================================================
---
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/Util.java
(added)
+++
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/Util.java
Thu Oct 27 09:06:52 2016
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.felix.serializer.impl;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+public class Util {
+ private Util() {} // prevent instantiation
+
+ public static byte [] readStream(InputStream is) throws IOException {
+ try {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ byte[] bytes = new byte[8192];
+
+ int length = 0;
+ int offset = 0;
+
+ while ((length = is.read(bytes, offset, bytes.length - offset)) !=
-1) {
+ offset += length;
+
+ if (offset == bytes.length) {
+ baos.write(bytes, 0, bytes.length);
+ offset = 0;
+ }
+ }
+ if (offset != 0) {
+ baos.write(bytes, 0, offset);
+ }
+ return baos.toByteArray();
+ } finally {
+ is.close();
+ }
+ }
+}
Modified:
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonDeserializingImpl.java
URL:
http://svn.apache.org/viewvc/felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonDeserializingImpl.java?rev=1766791&r1=1766790&r2=1766791&view=diff
==============================================================================
---
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonDeserializingImpl.java
(original)
+++
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonDeserializingImpl.java
Thu Oct 27 09:06:52 2016
@@ -24,7 +24,7 @@ import java.nio.charset.StandardCharsets
import java.util.Map;
import java.util.Scanner;
-import org.apache.felix.converter.impl.Util;
+import org.apache.felix.serializer.impl.Util;
import org.osgi.service.serializer.Deserializing;
import org.osgi.util.converter.ConversionException;
import org.osgi.util.converter.Converter;
Modified:
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonParser.java
URL:
http://svn.apache.org/viewvc/felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonParser.java?rev=1766791&r1=1766790&r2=1766791&view=diff
==============================================================================
---
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonParser.java
(original)
+++
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonParser.java
Thu Oct 27 09:06:52 2016
@@ -26,7 +26,7 @@ import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.apache.felix.converter.impl.Util;
+import org.apache.felix.serializer.impl.Util;
/**
* A very small JSON parser.
Modified:
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlDeserializingImpl.java
URL:
http://svn.apache.org/viewvc/felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlDeserializingImpl.java?rev=1766791&r1=1766790&r2=1766791&view=diff
==============================================================================
---
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlDeserializingImpl.java
(original)
+++
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlDeserializingImpl.java
Thu Oct 27 09:06:52 2016
@@ -23,7 +23,7 @@ import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
-import org.apache.felix.converter.impl.Util;
+import org.apache.felix.serializer.impl.Util;
import org.osgi.service.serializer.Deserializing;
import org.osgi.util.converter.ConversionException;
import org.osgi.util.converter.Converter;