Package org.apache.calcite.avatica

# Class AvaticaUtils

java.lang.Object
org.apache.calcite.avatica.AvaticaUtils

public class AvaticaUtils extends Object
Avatica utilities.

## Method Summary

Modifier and Type
Method
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 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.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Method Details

### discard

public static void discard(Object o)
Does nothing with its argument. Call this method when you have a value you are not interested in, but you don't want the compiler to warn that you are not using it.

### remark

public static <T> T remark(T remark)
Use this method to flag temporary code.

Example #1:

>      if (AvaticaUtils.remark("baz fixed") == null) {
>        baz();
>      }

Example #2:

>      /** @see AvaticaUtils#remark Remove before checking in */
>      void uselessMethod() {}

### upgrade

public static boolean upgrade(String remark)
Use this method to flag code that should be re-visited after upgrading a component.

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".

### primitiveList

public static List<?> primitiveList(Object array)
Adapts a primitive array into a `List`. For example, `asList(new double[2])` returns a `List&lt;Double&gt;`.

### camelToUpper

public static String camelToUpper(String name)
Converts a camelCase name into an upper-case underscore-separated name. For example, `camelToUpper("myJdbcDriver")` returns "MY_JDBC_DRIVER".

### toCamelCase

public static String toCamelCase(String name)
Converts an underscore-separated name into a camelCase name. For example, `uncamel("MY_JDBC_DRIVER")` returns "myJdbcDriver".

### box

public static Class box(Class clazz)
Returns the boxed class. For example, `box(int.class)` returns `java.lang.Integer`.

### instantiatePlugin

public static <T> T instantiatePlugin(Class<T> pluginClass, String className)
Creates an instance of a plugin class. First looks for a static member called INSTANCE, then calls a public default constructor.

If className contains a "#" instead looks for a static field.

Type Parameters:
  `T` - Class
Parameters:
  `pluginClass` - Class (or interface) to instantiate
  `className` - Name of implementing class
Returns:
  Plugin instance

### readFully

public static String readFully(InputStream inputStream) throws IOException
Reads the contents of an input stream and returns as a string.

Throws:
  `IOException`

### readFully

public static String readFully(InputStream inputStream, UnsynchronizedBuffer buffer) throws IOException
Reads the contents of an input stream and returns as a string.

Throws:
  `IOException`

### readFullyToBytes

public static byte[] readFullyToBytes(InputStream inputStream) throws IOException
Reads the contents of an input stream and returns as a string.

Throws:
  `IOException`

### readFullyToBytes

public static byte[] readFullyToBytes(InputStream inputStream, UnsynchronizedBuffer buffer) throws IOException
Reads the contents of an input stream and returns as a string.

Throws:
  `IOException`

### skipFully

public static void skipFully(InputStream inputStream) throws IOException
Reads and discards all data available on the InputStream.

Throws:
  `IOException`

### setLargeMaxRows

public static void setLargeMaxRows(Statement statement, long n) throws SQLException
Invokes `Statement#setLargeMaxRows`, falling back on `Statement.setMaxRows(int)` if the method does not exist (before JDK 1.8) or throws `UnsupportedOperationException`.

Throws:
  `SQLException`

### getLargeMaxRows

public static long getLargeMaxRows(Statement statement) throws SQLException
Invokes `Statement#getLargeMaxRows`, falling back on `Statement.getMaxRows()` if the method does not exist (before JDK 1.8) or throws `UnsupportedOperationException`.

Throws:
  `SQLException`

### getLargeUpdateCount

public static long getLargeUpdateCount(Statement statement) throws SQLException
Invokes `Statement#getLargeUpdateCount`, falling back on `Statement.getUpdateCount()` if the method does not exist (before JDK 1.8) or throws `UnsupportedOperationException`.

Throws:
  `SQLException`

### executeLargeBatch

public static long[] executeLargeBatch(Statement statement) throws SQLException
Invokes `Statement#executeLargeBatch`, falling back on `Statement.executeBatch()` if the method does not exist (before JDK 1.8) or throws `UnsupportedOperationException`.

Throws:
  `SQLException`

### unique

public static String unique(String base)
Generates a string that is unique in the execution of the JVM. It is used by tests to ensure that they create distinct temporary tables. The strings are never thrown away, so don't put too much in there! Thread safe.

### toSaturatedInt

public 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`.

### toSaturatedInts

public 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`.

Parameters:
  `longs` - An array of `long`s
Returns:
  An array of `int`s

### toLongs

public static long[] toLongs(int[] ints)
Converts an array of `int` values to an array of `long` values.