From fe874c946db04afeca4ecf3a800fa5e4e3b14881 Mon Sep 17 00:00:00 2001 From: rob bygrave Date: Wed, 23 Dec 2020 20:22:50 +1300 Subject: [PATCH] #2140 - Bump ebean-migration dependency of ebean-ddl-generator to 12.4.0 (update ebean-test) --- ebean-core/pom.xml | 2 +- ebean-ddl-generator/pom.xml | 2 +- ebean-test/pom.xml | 2 +- .../src/main/java/io/ebean/test/DbJson.java | 1 - .../src/main/java/io/ebean/test/IOUtils.java | 62 +++++++++++++++++++ 5 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 ebean-test/src/main/java/io/ebean/test/IOUtils.java diff --git a/ebean-core/pom.xml b/ebean-core/pom.xml index 94223d0cf..d1c6bb031 100644 --- a/ebean-core/pom.xml +++ b/ebean-core/pom.xml @@ -70,7 +70,7 @@ io.ebean ebean-migration - 12.2.0 + 12.4.0 test diff --git a/ebean-ddl-generator/pom.xml b/ebean-ddl-generator/pom.xml index bee92b994..1d94dbab8 100644 --- a/ebean-ddl-generator/pom.xml +++ b/ebean-ddl-generator/pom.xml @@ -23,7 +23,7 @@ io.ebean ebean-migration - 12.2.0 + 12.4.0 diff --git a/ebean-test/pom.xml b/ebean-test/pom.xml index 992aff7fa..f9d1e012d 100644 --- a/ebean-test/pom.xml +++ b/ebean-test/pom.xml @@ -91,7 +91,7 @@ org.postgresql postgresql - 42.2.12 + 42.2.18 test diff --git a/ebean-test/src/main/java/io/ebean/test/DbJson.java b/ebean-test/src/main/java/io/ebean/test/DbJson.java index b7fae39bb..79de39099 100644 --- a/ebean-test/src/main/java/io/ebean/test/DbJson.java +++ b/ebean-test/src/main/java/io/ebean/test/DbJson.java @@ -1,7 +1,6 @@ package io.ebean.test; import io.ebean.DB; -import io.ebean.migration.util.IOUtils; import java.io.IOException; import java.io.InputStream; diff --git a/ebean-test/src/main/java/io/ebean/test/IOUtils.java b/ebean-test/src/main/java/io/ebean/test/IOUtils.java new file mode 100644 index 000000000..79b706706 --- /dev/null +++ b/ebean-test/src/main/java/io/ebean/test/IOUtils.java @@ -0,0 +1,62 @@ +package io.ebean.test; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.charset.StandardCharsets; + +/** + * Utilities for IO. + */ +class IOUtils { + + /** + * Reads the entire contents of the specified input stream and return them as UTF-8 string. + */ + static String readUtf8(InputStream in) throws IOException { + return bytesToUtf8(read(in)); + } + + /** + * Reads the entire contents of the specified input stream and returns them as a byte array. + */ + private static byte[] read(InputStream in) throws IOException { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + pump(in, buffer); + return buffer.toByteArray(); + } + + /** + * Returns the UTF-8 string corresponding to the specified bytes. + */ + private static String bytesToUtf8(byte[] data) { + return new String(data, StandardCharsets.UTF_8); + } + + /** + * Reads data from the specified input stream and copies it to the specified + * output stream, until the input stream is at EOF. Both streams are then + * closed. + */ + private static void pump(InputStream in, OutputStream out) throws IOException { + if (in == null) throw new IOException("Input stream is null"); + if (out == null) throw new IOException("Output stream is null"); + try { + try { + byte[] buffer = new byte[4096]; + for (; ; ) { + int bytes = in.read(buffer); + if (bytes < 0) { + break; + } + out.write(buffer, 0, bytes); + } + } finally { + in.close(); + } + } finally { + out.close(); + } + } +}