- * ES: We use 1024 bytes since we mainly use this to build json/smile
- * content in memory, and rarely does the 32 byte default in ByteArrayOutputStream fits...
- */
- public FastByteArrayOutputStream() {
- this(1024);
- }
-
- /**
- * Creates a new byte array output stream, with a buffer capacity of
- * the specified size, in bytes.
- *
- * @param size the initial size.
- */
- public FastByteArrayOutputStream(int size) {
- Assert.isTrue(size >= 0, "Negative initial size: " + size);
- data = new BytesArray(size);
- }
-
- public FastByteArrayOutputStream(BytesArray data) {
- this.data = data;
- }
-
- /**
- * Writes the specified byte to this byte array output stream.
- *
- * @param b the byte to be written.
- */
- public void write(int b) {
- data.add(b);
- }
-
- /**
- * Writes len
bytes from the specified byte array
- * starting at offset off
to this byte array output stream.
- *
- * NO checks for bounds, parameters must be ok!
- *
- * @param b the data.
- * @param off the start offset in the data.
- * @param len the number of bytes to write.
- */
- public void write(byte b[], int off, int len) {
- data.add(b, off, len);
- }
-
- /**
- * Writes the complete contents of this byte array output stream to
- * the specified output stream argument, as if by calling the output
- * stream's write method using out.write(buf, 0, count)
.
- *
- * @param out the output stream to which to write the data.
- * @throws IOException if an I/O error occurs.
- */
- public void writeTo(OutputStream out) throws IOException {
- out.write(data.bytes, 0, data.size);
- }
-
- public BytesArray bytes() {
- return data;
- }
-
- public void setBytes(byte[] data, int size) {
- this.data.bytes(data, size);
- }
-
- /**
- * Returns the current size of the buffer.
- *
- * @return the value of the count
field, which is the number
- * of valid bytes in this output stream.
- * @see java.io.ByteArrayOutputStream#count
- */
- public long size() {
- return data.length();
- }
-
- /**
- * Resets the count
field of this byte array output
- * stream to zero, so that all currently accumulated output in the
- * output stream is discarded. The output stream can be used again,
- * reusing the already capacity buffer space.
- *
- * @see java.io.ByteArrayInputStream#count
- */
- public void reset() {
- data.reset();
- }
-
- public String toString() {
- return data.toString();
- }
-
- /**
- * Closing a ByteArrayOutputStream has no effect. The methods in
- * this class can be called after the stream has been closed without
- * generating an IOException.
- */
- public void close() throws IOException {}
-}
\ No newline at end of file
diff --git a/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/util/IOUtils.java b/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/util/IOUtils.java
deleted file mode 100644
index e4307236856..00000000000
--- a/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/util/IOUtils.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License;
- * you may not use this file except in compliance with the Elastic License.
- */
-package org.elasticsearch.xpack.sql.jdbc.util;
-
-import java.io.Closeable;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringReader;
-import java.util.Properties;
-
-public abstract class IOUtils {
-
- public static Properties propsFromString(String source) {
- Properties copy = new Properties();
- if (source != null) {
- try {
- copy.load(new StringReader(source));
- } catch (IOException ex) {
- throw new RuntimeException(ex);
- }
- }
- return copy;
- }
-
- public static void close(Closeable closable) {
- if (closable != null) {
- try {
- closable.close();
- } catch (IOException e) {
- // silently ignore
- }
- }
- }
-
-
- public static String asString(InputStream in) throws IOException {
- return asBytes(in).toString();
- }
-
- public static BytesArray asBytes(InputStream in) throws IOException {
- BytesArray ba = unwrapStreamBuffer(in);
- if (ba != null) {
- return ba;
- }
- return asBytes(new BytesArray(in.available()), in);
- }
-
- public static BytesArray asBytes(BytesArray ba, InputStream input) throws IOException {
- BytesArray buf = unwrapStreamBuffer(input);
- if (buf != null) {
- ba.bytes(buf);
- return ba;
- }
-
- FastByteArrayOutputStream bos = new FastByteArrayOutputStream(ba);
- byte[] buffer = new byte[1024];
- int read = 0;
- try (InputStream in = input) {
- while ((read = in.read(buffer)) != -1) {
- bos.write(buffer, 0, read);
- }
- } finally {
- // non needed but used to avoid the warnings
- bos.close();
- }
- return bos.bytes();
- }
-
- private static BytesArray unwrapStreamBuffer(InputStream in) {
- if (in instanceof FastByteArrayInputStream) {
- return ((FastByteArrayInputStream) in).data;
- }
-
- return null;
- }
-}
\ No newline at end of file
diff --git a/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/util/UnicodeUtil.java b/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/util/UnicodeUtil.java
deleted file mode 100644
index 1e2a2a0ffce..00000000000
--- a/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/util/UnicodeUtil.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License;
- * you may not use this file except in compliance with the Elastic License.
- */
-package org.elasticsearch.xpack.sql.jdbc.util;
-
-public class UnicodeUtil {
-
-
- public static final int UNI_SUR_HIGH_START = 0xD800;
- public static final int UNI_SUR_HIGH_END = 0xDBFF;
- public static final int UNI_SUR_LOW_START = 0xDC00;
- public static final int UNI_SUR_LOW_END = 0xDFFF;
- public static final int UNI_REPLACEMENT_CHAR = 0xFFFD;
-
- private static final long HALF_SHIFT = 10;
-
- private static final int SURROGATE_OFFSET = Character.MIN_SUPPLEMENTARY_CODE_POINT - (UNI_SUR_HIGH_START << HALF_SHIFT) - UNI_SUR_LOW_START;
-
- /** Encode characters from this String, starting at offset
- * for length characters. Output to the destination array
- * will begin at {@code outOffset}. It is the responsibility of the
- * caller to make sure that the destination array is large enough.
- *
- * note this method returns the final output offset (outOffset + number of bytes written)
- */
- public static int UTF16toUTF8(final CharSequence s, final int offset, final int length, byte[] out, int outOffset) {
- final int end = offset + length;
-
- int upto = outOffset;
- for (int i = offset; i < end; i++) {
- final int code = (int) s.charAt(i);
-
- if (code < 0x80)
- out[upto++] = (byte) code;
- else if (code < 0x800) {
- out[upto++] = (byte) (0xC0 | (code >> 6));
- out[upto++] = (byte) (0x80 | (code & 0x3F));
- }
- else if (code < 0xD800 || code > 0xDFFF) {
- out[upto++] = (byte) (0xE0 | (code >> 12));
- out[upto++] = (byte) (0x80 | ((code >> 6) & 0x3F));
- out[upto++] = (byte) (0x80 | (code & 0x3F));
- }
- else {
- // surrogate pair
- // confirm valid high surrogate
- if (code < 0xDC00 && (i < end - 1)) {
- int utf32 = (int) s.charAt(i + 1);
- // confirm valid low surrogate and write pair
- if (utf32 >= 0xDC00 && utf32 <= 0xDFFF) {
- utf32 = (code << 10) + utf32 + SURROGATE_OFFSET;
- i++;
- out[upto++] = (byte) (0xF0 | (utf32 >> 18));
- out[upto++] = (byte) (0x80 | ((utf32 >> 12) & 0x3F));
- out[upto++] = (byte) (0x80 | ((utf32 >> 6) & 0x3F));
- out[upto++] = (byte) (0x80 | (utf32 & 0x3F));
- continue;
- }
- }
- // replace unpaired surrogate or out-of-order low surrogate
- // with substitution character
- out[upto++] = (byte) 0xEF;
- out[upto++] = (byte) 0xBF;
- out[upto++] = (byte) 0xBD;
- }
- }
- //assert matches(s, offset, length, out, upto);
- return upto;
- }
-}
diff --git a/sql/jdbc/src/test/java/org/elasticsearch/xpack/sql/jdbc/framework/DataLoader.java b/sql/jdbc/src/test/java/org/elasticsearch/xpack/sql/jdbc/framework/DataLoader.java
index 657c131ed51..bba8871a77b 100644
--- a/sql/jdbc/src/test/java/org/elasticsearch/xpack/sql/jdbc/framework/DataLoader.java
+++ b/sql/jdbc/src/test/java/org/elasticsearch/xpack/sql/jdbc/framework/DataLoader.java
@@ -72,8 +72,8 @@ public class DataLoader {
}
bulk.append("}\n");
});
- client.performRequest("POST", "/test_emp/emp/_bulk", singletonMap("refresh", "true"), new StringEntity(bulk.toString(), ContentType.APPLICATION_JSON));
-
+ client.performRequest("POST", "/test_emp/emp/_bulk", singletonMap("refresh", "true"),
+ new StringEntity(bulk.toString(), ContentType.APPLICATION_JSON));
}
private static void csvToLines(String name, CheckedBiConsumer, List