mirror of https://github.com/apache/nifi.git
NIFI-5933 Stopped using sun's IOUtils. Using apahce's instead.
NIFI-5933 Removed unused file with sun.* import NIFI-5933 Removed unsafe of sun.*. NIFI-5933 Added openjdk8 to test This closes #3234 Signed-off-by: Mike Thomsen <mikerthomsen@gmail.com>
This commit is contained in:
parent
1705ee3b66
commit
ba642485cc
|
@ -25,6 +25,7 @@ os:
|
|||
|
||||
jdk:
|
||||
- oraclejdk8
|
||||
- openjdk8
|
||||
|
||||
# Caches mvn repository in order to speed upbuilds
|
||||
cache:
|
||||
|
|
|
@ -34,6 +34,11 @@
|
|||
<artifactId>avro</artifactId>
|
||||
<version>1.8.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.ben-manes.caffeine</groupId>
|
||||
<artifactId>caffeine</artifactId>
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.apache.nifi.serialization.record.RecordFieldType;
|
|||
import org.apache.nifi.serialization.record.RecordSchema;
|
||||
import org.apache.nifi.serialization.record.type.RecordDataType;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import sun.misc.IOUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -39,7 +39,7 @@ public class InferenceSchemaStrategy implements JsonSchemaAccessStrategy {
|
|||
|
||||
@Override
|
||||
public RecordSchema getSchema(Map<String, String> variables, InputStream contentStream, RecordSchema readSchema) throws SchemaNotFoundException, IOException {
|
||||
byte[] bytes = IOUtils.readFully(contentStream, -1, true);
|
||||
byte[] bytes = IOUtils.toByteArray(contentStream);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
return convertSchema(mapper.readValue(bytes, Map.class));
|
||||
|
|
|
@ -1,104 +1,68 @@
|
|||
/*
|
||||
* 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.nifi.hbase.util;
|
||||
|
||||
import sun.misc.Unsafe;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.charset.Charset;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
|
||||
public class Bytes {
|
||||
|
||||
public static String toString(byte[] b) {
|
||||
return b == null ? null : toString(b, 0, b.length);
|
||||
}
|
||||
|
||||
public static String toString(byte[] b1, String sep, byte[] b2) {
|
||||
return toString(b1, 0, b1.length) + sep + toString(b2, 0, b2.length);
|
||||
}
|
||||
|
||||
public static String toString(byte[] b, int off, int len) {
|
||||
if (b == null) {
|
||||
return null;
|
||||
} else {
|
||||
return len == 0 ? "" : new String(b, off, len, Charset.forName("UTF-8"));
|
||||
}
|
||||
}
|
||||
|
||||
public static long toLong(byte[] bytes) {
|
||||
return toLong(bytes, 0, 8);
|
||||
}
|
||||
|
||||
private static long toLong(byte[] bytes, int offset, int length) {
|
||||
if (length == 8 && offset + length <= bytes.length) {
|
||||
if (theUnsafe != null) {
|
||||
return toLongUnsafe(bytes, offset);
|
||||
} else {
|
||||
long l = 0L;
|
||||
|
||||
for(int i = offset; i < offset + length; ++i) {
|
||||
l <<= 8;
|
||||
l ^= (long)(bytes[i] & 255);
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
} else {
|
||||
throw explainWrongLengthOrOffset(bytes, offset, length, 8);
|
||||
}
|
||||
}
|
||||
|
||||
private static long toLongUnsafe(byte[] bytes, int offset) {
|
||||
final boolean littleEndian = ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN);
|
||||
final int BYTE_ARRAY_BASE_OFFSET = theUnsafe.arrayBaseOffset(byte[].class);
|
||||
|
||||
if (littleEndian) {
|
||||
return Long.reverseBytes(theUnsafe.getLong(bytes,
|
||||
(long) offset + BYTE_ARRAY_BASE_OFFSET));
|
||||
} else {
|
||||
return theUnsafe.getLong(bytes,
|
||||
(long) offset + BYTE_ARRAY_BASE_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
private static IllegalArgumentException explainWrongLengthOrOffset(byte[] bytes, int offset, int length, int expectedLength) {
|
||||
String reason;
|
||||
if (length != expectedLength) {
|
||||
reason = "Wrong length: " + length + ", expected " + expectedLength;
|
||||
} else {
|
||||
reason = "offset (" + offset + ") + length (" + length + ") exceed the" + " capacity of the array: " + bytes.length;
|
||||
}
|
||||
|
||||
return new IllegalArgumentException(reason);
|
||||
}
|
||||
|
||||
private static final Unsafe theUnsafe = (Unsafe) AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||
public Object run() {
|
||||
try {
|
||||
Field f = Unsafe.class.getDeclaredField("theUnsafe");
|
||||
f.setAccessible(true);
|
||||
return f.get((Object)null);
|
||||
} catch (NoSuchFieldException | IllegalAccessException var2) {
|
||||
throw new Error();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
/*
|
||||
* 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.nifi.hbase.util;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
public class Bytes {
|
||||
|
||||
public static String toString(byte[] b) {
|
||||
return b == null ? null : toString(b, 0, b.length);
|
||||
}
|
||||
|
||||
public static String toString(byte[] b1, String sep, byte[] b2) {
|
||||
return toString(b1, 0, b1.length) + sep + toString(b2, 0, b2.length);
|
||||
}
|
||||
|
||||
public static String toString(byte[] b, int off, int len) {
|
||||
if (b == null) {
|
||||
return null;
|
||||
} else {
|
||||
return len == 0 ? "" : new String(b, off, len, Charset.forName("UTF-8"));
|
||||
}
|
||||
}
|
||||
|
||||
public static long toLong(byte[] bytes) {
|
||||
return toLong(bytes, 0, 8);
|
||||
}
|
||||
|
||||
private static long toLong(byte[] bytes, int offset, int length) {
|
||||
if (length == 8 && offset + length <= bytes.length) {
|
||||
long l = 0L;
|
||||
|
||||
for(int i = offset; i < offset + length; ++i) {
|
||||
l <<= 8;
|
||||
l ^= (long)(bytes[i] & 255);
|
||||
}
|
||||
|
||||
return l;
|
||||
} else {
|
||||
throw explainWrongLengthOrOffset(bytes, offset, length, 8);
|
||||
}
|
||||
}
|
||||
|
||||
private static IllegalArgumentException explainWrongLengthOrOffset(byte[] bytes, int offset, int length, int expectedLength) {
|
||||
String reason;
|
||||
if (length != expectedLength) {
|
||||
reason = "Wrong length: " + length + ", expected " + expectedLength;
|
||||
} else {
|
||||
reason = "offset (" + offset + ") + length (" + length + ") exceed the" + " capacity of the array: " + bytes.length;
|
||||
}
|
||||
|
||||
return new IllegalArgumentException(reason);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* 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.nifi.processors.kafka.pubsub;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import sun.misc.Unsafe;
|
||||
|
||||
class TestUtils {
|
||||
|
||||
public static void setFinalField(Field field, Object instance, Object newValue) throws Exception {
|
||||
field.setAccessible(true);
|
||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
||||
modifiersField.setAccessible(true);
|
||||
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
|
||||
field.set(instance, newValue);
|
||||
}
|
||||
|
||||
static Unsafe getUnsafe() {
|
||||
try {
|
||||
Field f = Unsafe.class.getDeclaredField("theUnsafe");
|
||||
f.setAccessible(true);
|
||||
return (Unsafe) f.get(null);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue