public class AvaticaUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
private static Map<Class,Class> |
BOX |
private static MethodHandle |
EXECUTE_LARGE_BATCH |
private static MethodHandle |
GET_LARGE_MAX_ROWS |
private static MethodHandle |
GET_LARGE_UPDATE_COUNT |
private static ThreadLocal<byte[]> |
PER_THREAD_BUFFER |
private static MethodHandle |
SET_LARGE_MAX_ROWS |
private static Set<String> |
UNIQUE_STRINGS |
| Modifier | Constructor and Description |
|---|---|
private |
AvaticaUtils() |
| Modifier and Type | Method and Description |
|---|---|
(package private) static byte[] |
_readFully(InputStream inputStream,
UnsynchronizedBuffer buffer)
Reads the contents of an input stream and returns a byte array.
|
static Class |
box(Class clazz)
Returns the boxed class.
|
static String |
camelToUpper(String name)
Converts a camelCase name into an upper-case underscore-separated name.
|
static void |
discard(Object o)
Does nothing with its argument.
|
static long[] |
executeLargeBatch(Statement statement)
Invokes
Statement#executeLargeBatch, falling back on
Statement.executeBatch() if the method does not exist
(before JDK 1.8) or throws UnsupportedOperationException. |
static long |
getLargeMaxRows(Statement statement)
Invokes
Statement#getLargeMaxRows, falling back on
Statement.getMaxRows() if the method does not exist (before
JDK 1.8) or throws UnsupportedOperationException. |
static long |
getLargeUpdateCount(Statement statement)
Invokes
Statement#getLargeUpdateCount, falling back on
Statement.getUpdateCount() if the method does not exist (before
JDK 1.8) or throws UnsupportedOperationException. |
static <T> T |
instantiatePlugin(Class<T> pluginClass,
String className)
Creates an instance of a plugin class.
|
private static MethodHandle |
method(Class returnType,
Class targetType,
String name,
Class... argTypes) |
static List<?> |
primitiveList(Object array)
Adapts a primitive array into a
List. |
static String |
readFully(InputStream inputStream)
Reads the contents of an input stream and returns as a string.
|
static String |
readFully(InputStream inputStream,
UnsynchronizedBuffer buffer)
Reads the contents of an input stream and returns as a string.
|
static byte[] |
readFullyToBytes(InputStream inputStream)
Reads the contents of an input stream and returns as a string.
|
static byte[] |
readFullyToBytes(InputStream inputStream,
UnsynchronizedBuffer buffer)
Reads the contents of an input stream and returns as a string.
|
static <T> T |
remark(T remark)
Use this method to flag temporary code.
|
static void |
setLargeMaxRows(Statement statement,
long n)
Invokes
Statement#setLargeMaxRows, falling back on
Statement.setMaxRows(int) if the method does not exist (before
JDK 1.8) or throws UnsupportedOperationException. |
static String |
toCamelCase(String name)
Converts an underscore-separated name into a camelCase name.
|
static long[] |
toLongs(int[] ints)
Converts an array of
int values to an array of long
values. |
static int |
toSaturatedInt(long value)
Converts a
long to int, rounding as little as possible
if the value is outside the legal range for an int. |
static int[] |
toSaturatedInts(long[] longs)
Converts an array of
long values to an array of int
values, truncating values outside the legal range for an int
to Integer.MIN_VALUE or Integer.MAX_VALUE. |
static String |
unique(String base)
Generates a string that is unique in the execution of the JVM.
|
static boolean |
upgrade(String remark)
Use this method to flag code that should be re-visited after upgrading
a component.
|
private static final MethodHandle SET_LARGE_MAX_ROWS
private static final MethodHandle GET_LARGE_MAX_ROWS
private static final MethodHandle GET_LARGE_UPDATE_COUNT
private static final MethodHandle EXECUTE_LARGE_BATCH
private static final ThreadLocal<byte[]> PER_THREAD_BUFFER
private static MethodHandle method(Class returnType, Class targetType, String name, Class... argTypes)
public static void discard(Object o)
public static <T> T remark(T remark)
Example #1:
if (AvaticaUtils.remark("baz fixed") == null) {
baz();
}
Example #2:
/** @see AvaticaUtils#remark Remove before checking in */
void uselessMethod() {}
public static boolean upgrade(String remark)
If the intended change is that a class or member be removed, flag
instead using a Deprecated annotation followed by a comment such as
"to be removed before 2.0".
public static List<?> primitiveList(Object array)
List. For example,
asList(new double[2]) returns a List<Double>.public static String camelToUpper(String name)
camelToUpper("myJdbcDriver") returns
"MY_JDBC_DRIVER".public static String toCamelCase(String name)
uncamel("MY_JDBC_DRIVER") returns "myJdbcDriver".public static Class box(Class clazz)
box(int.class)
returns java.lang.Integer.public static <T> T instantiatePlugin(Class<T> pluginClass, String className)
If className contains a "#" instead looks for a static field.
T - ClasspluginClass - Class (or interface) to instantiateclassName - Name of implementing classpublic static String readFully(InputStream inputStream) throws IOException
IOExceptionpublic static String readFully(InputStream inputStream, UnsynchronizedBuffer buffer) throws IOException
IOExceptionpublic static byte[] readFullyToBytes(InputStream inputStream) throws IOException
IOExceptionpublic static byte[] readFullyToBytes(InputStream inputStream, UnsynchronizedBuffer buffer) throws IOException
IOExceptionstatic byte[] _readFully(InputStream inputStream, UnsynchronizedBuffer buffer) throws IOException
inputStream - the input to read from.IOExceptionpublic static void setLargeMaxRows(Statement statement, long n) throws SQLException
Statement#setLargeMaxRows, falling back on
Statement.setMaxRows(int) if the method does not exist (before
JDK 1.8) or throws UnsupportedOperationException.SQLExceptionpublic static long getLargeMaxRows(Statement statement) throws SQLException
Statement#getLargeMaxRows, falling back on
Statement.getMaxRows() if the method does not exist (before
JDK 1.8) or throws UnsupportedOperationException.SQLExceptionpublic static long getLargeUpdateCount(Statement statement) throws SQLException
Statement#getLargeUpdateCount, falling back on
Statement.getUpdateCount() if the method does not exist (before
JDK 1.8) or throws UnsupportedOperationException.SQLExceptionpublic static long[] executeLargeBatch(Statement statement) throws SQLException
Statement#executeLargeBatch, falling back on
Statement.executeBatch() if the method does not exist
(before JDK 1.8) or throws UnsupportedOperationException.SQLExceptionpublic static String unique(String base)
public static int toSaturatedInt(long value)
long to int, rounding as little as possible
if the value is outside the legal range for an int.public static int[] toSaturatedInts(long[] longs)
long values to an array of int
values, truncating values outside the legal range for an int
to Integer.MIN_VALUE or Integer.MAX_VALUE.longs - An array of longsintspublic static long[] toLongs(int[] ints)
int values to an array of long
values.Copyright © 2012–2017 The Apache Software Foundation. All rights reserved.