Package org.apache.calcite.avatica

## Class AvaticaUtils

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

    public class AvaticaUtils
    extends java.lang.Object

Avatica utilities.

### Field Summary

Fields
`private static java.util.Map<java.lang.Class,​java.lang.Class>` `BOX`
`private static java.lang.invoke.MethodHandle` `EXECUTE_LARGE_BATCH`
`private static java.lang.invoke.MethodHandle` `GET_LARGE_MAX_ROWS`
`private static java.lang.invoke.MethodHandle` `GET_LARGE_UPDATE_COUNT`
`private static java.lang.ThreadLocal<byte[]>` `PER_THREAD_BUFFER`
`private static java.lang.invoke.MethodHandle` `SET_LARGE_MAX_ROWS`
`private static java.util.Set<java.lang.String>` `UNIQUE_STRINGS`

### Constructor Summary

Constructors
`private` `AvaticaUtils()`

### Method Summary

All Methods Static Methods Concrete Methods
`(package private) static byte[]` `_readFully​(java.io.InputStream inputStream, UnsynchronizedBuffer buffer)` Reads the contents of an input stream and returns a byte array.
`static java.lang.Class` `box​(java.lang.Class clazz)` Returns the boxed class.
`static java.lang.String` `camelToUpper​(java.lang.String name)` Converts a camelCase name into an upper-case underscore-separated name.
`static void` `discard​(java.lang.Object o)` Does nothing with its argument.
`static long[]` `executeLargeBatch​(java.sql.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​(java.sql.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​(java.sql.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​(java.lang.Class<T> pluginClass, java.lang.String className)` Creates an instance of a plugin class.
`private static java.lang.invoke.MethodHandle` `method​(java.lang.Class returnType, java.lang.Class targetType, java.lang.String name, java.lang.Class... argTypes)`
`static java.util.List<?>` `primitiveList​(java.lang.Object array)` Adapts a primitive array into a `List`.
`static java.lang.String` `readFully​(java.io.InputStream inputStream)` Reads the contents of an input stream and returns as a string.
`static java.lang.String` `readFully​(java.io.InputStream inputStream, UnsynchronizedBuffer buffer)` Reads the contents of an input stream and returns as a string.
`static byte[]` `readFullyToBytes​(java.io.InputStream inputStream)` Reads the contents of an input stream and returns as a string.
`static byte[]` `readFullyToBytes​(java.io.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​(java.sql.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 java.lang.String` `toCamelCase​(java.lang.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 java.lang.String` `unique​(java.lang.String base)` Generates a string that is unique in the execution of the JVM.
`static boolean` `upgrade​(java.lang.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`

### Field Detail

#### BOX

    private static final java.util.Map<java.lang.Class,​java.lang.Class> BOX

#### SET_LARGE_MAX_ROWS

    private static final java.lang.invoke.MethodHandle SET_LARGE_MAX_ROWS

#### GET_LARGE_MAX_ROWS

    private static final java.lang.invoke.MethodHandle GET_LARGE_MAX_ROWS

#### GET_LARGE_UPDATE_COUNT

    private static final java.lang.invoke.MethodHandle GET_LARGE_UPDATE_COUNT

#### EXECUTE_LARGE_BATCH

    private static final java.lang.invoke.MethodHandle EXECUTE_LARGE_BATCH

#### UNIQUE_STRINGS

    private static final java.util.Set<java.lang.String> UNIQUE_STRINGS

#### PER_THREAD_BUFFER

    private static final java.lang.ThreadLocal<byte[]> PER_THREAD_BUFFER

### Constructor Detail

#### AvaticaUtils

    private AvaticaUtils()

### Method Detail

#### method

    private static java.lang.invoke.MethodHandle method​(java.lang.Class returnType,
                                                        java.lang.Class targetType,
                                                        java.lang.String name,
                                                        java.lang.Class... argTypes)

#### discard

    public static void discard​(java.lang.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​(java.lang.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 java.util.List<?> primitiveList​(java.lang.Object array)

Adapts a primitive array into a `List`. For example, `asList(new double[2])` returns a `List&lt;Double&gt;`.

#### camelToUpper

    public static java.lang.String camelToUpper​(java.lang.String name)

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

#### toCamelCase

    public static java.lang.String toCamelCase​(java.lang.String name)

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

#### box

    public static java.lang.Class box​(java.lang.Class clazz)

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

#### instantiatePlugin

    public static <T> T instantiatePlugin​(java.lang.Class<T> pluginClass,
                                          java.lang.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 java.lang.String readFully​(java.io.InputStream inputStream)
                                      throws java.io.IOException

Reads the contents of an input stream and returns as a string.

Throws:
  `java.io.IOException`

#### readFully

    public static java.lang.String readFully​(java.io.InputStream inputStream,
                                             UnsynchronizedBuffer buffer)
                                      throws java.io.IOException

Reads the contents of an input stream and returns as a string.

Throws:
  `java.io.IOException`

#### readFullyToBytes

    public static byte[] readFullyToBytes​(java.io.InputStream inputStream)
                                   throws java.io.IOException

Reads the contents of an input stream and returns as a string.

Throws:
  `java.io.IOException`

#### readFullyToBytes

    public static byte[] readFullyToBytes​(java.io.InputStream inputStream,
                                          UnsynchronizedBuffer buffer)
                                   throws java.io.IOException

Reads the contents of an input stream and returns as a string.

Throws:
  `java.io.IOException`

#### _readFully

    static byte[] _readFully​(java.io.InputStream inputStream,
                             UnsynchronizedBuffer buffer)
                      throws java.io.IOException

Reads the contents of an input stream and returns a byte array.

Parameters:
  `inputStream` - the input to read from.
Returns:
  A byte array whose length is equal to the number of bytes contained.
Throws:
  `java.io.IOException`

#### setLargeMaxRows

    public static void setLargeMaxRows​(java.sql.Statement statement,
                                       long n)
                                throws java.sql.SQLException

Invokes `Statement#setLargeMaxRows`, falling back on `Statement.setMaxRows(int)` if the method does not exist (before JDK 1.8) or throws `UnsupportedOperationException`.

Throws:
  `java.sql.SQLException`

#### getLargeMaxRows

    public static long getLargeMaxRows​(java.sql.Statement statement)
                                throws java.sql.SQLException

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

Throws:
  `java.sql.SQLException`

#### getLargeUpdateCount

    public static long getLargeUpdateCount​(java.sql.Statement statement)
                                    throws java.sql.SQLException

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

Throws:
  `java.sql.SQLException`

#### executeLargeBatch

    public static long[] executeLargeBatch​(java.sql.Statement statement)
                                    throws java.sql.SQLException

Invokes `Statement#executeLargeBatch`, falling back on `Statement.executeBatch()` if the method does not exist (before JDK 1.8) or throws `UnsupportedOperationException`.

Throws:
  `java.sql.SQLException`

#### unique

    public static java.lang.String unique​(java.lang.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.