public class AvaticaUtils extends Object
Modifier and Type | Method and Description |
---|---|
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.
|
static String |
newString(byte[] bytes,
Charset charset) |
static String |
newString(byte[] bytes,
String charsetName) |
static String |
newStringUtf8(byte[] bytes) |
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 void |
skipFully(InputStream inputStream)
Reads and discards all data available on the InputStream.
|
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.
|
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)
First looks for a static member called "INSTANCE
",
then calls a public default constructor.
If className
contains a "#", instead looks for a static field.
In the "#" case, if the static field is a ThreadLocal
, this
method dereferences the ThreadLocal
by calling
ThreadLocal.get()
. This behavior allows, for example, client code
to pass an object to a JDBC driver. The JDBC driver needs to be running in
the same JVM and the same thread as the client.
T
- ClasspluginClass
- Class (or interface) to instantiateclassName
- Name of implementing classpublic static String readFully(InputStream inputStream) throws IOException
IOException
public static String readFully(InputStream inputStream, UnsynchronizedBuffer buffer) throws IOException
IOException
public static byte[] readFullyToBytes(InputStream inputStream) throws IOException
IOException
public static byte[] readFullyToBytes(InputStream inputStream, UnsynchronizedBuffer buffer) throws IOException
IOException
public static void skipFully(InputStream inputStream) throws IOException
IOException
public 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
.SQLException
public 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
.SQLException
public 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
.SQLException
public 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
.SQLException
public 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 long
sint
spublic static long[] toLongs(int[] ints)
int
values to an array of long
values.public static String newStringUtf8(byte[] bytes)
public static String newString(byte[] bytes, String charsetName) throws UnsupportedEncodingException
UnsupportedEncodingException
Copyright © 2012-2024 Apache Software Foundation. All Rights Reserved.