New Upstream Release - libsejda-commons-java
Ready changes
Summary
Merged new upstream version: 2.0.0 (was: 1.1.7).
Resulting package
Built on 2022-12-14T15:43 (took 3m32s)
The resulting binary packages can be installed (if you have the apt repository enabled) by running one of:
apt install -t fresh-releases libsejda-commons-java
Lintian Result
Diff
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
new file mode 100644
index 0000000..b1a55a8
--- /dev/null
+++ b/.github/workflows/build.yml
@@ -0,0 +1,22 @@
+name: build
+
+on: [push]
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ java: ['17', '18']
+ name: JDK ${{ matrix.java }}
+
+ steps:
+ - uses: actions/checkout@v3
+ - name: Set up JDK
+ uses: actions/setup-java@v3
+ with:
+ java-version: ${{ matrix.java }}
+ distribution: 'temurin'
+ cache: 'maven'
+ - name: Build with Maven
+ run: mvn --batch-mode --update-snapshots verify
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 24eb861..1de84b3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,7 @@
.project
.launch
.settings/
+.idea/
target/
.externalToolBuilders/
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 547d93e..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,7 +0,0 @@
-language: java
-sudo: false
-jdk:
- - openjdk8
-notifications:
- email:
- - info@sejda.org
diff --git a/README.md b/README.md
index caffa95..35f1786 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
-sejda-commons (http://www.sejda.org)
+sejda-commons (https://www.sejda.org)
=====
-[![Build Status](https://travis-ci.org/torakiki/sejda-io.png)](https://travis-ci.org/torakiki/sejda-commons)
+![Build Status](https://github.com/torakiki/sejda-commons/actions/workflows/build.yml/badge.svg)
[![License](http://img.shields.io/badge/license-APLv2-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)
A collection of utilities and common classes.
diff --git a/debian/changelog b/debian/changelog
index c05fa62..940a209 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+libsejda-commons-java (2.0.0-1) UNRELEASED; urgency=low
+
+ * New upstream release.
+
+ -- Debian Janitor <janitor@jelmer.uk> Wed, 14 Dec 2022 15:40:09 -0000
+
libsejda-commons-java (1.1.7-1) unstable; urgency=medium
* New upstream version 1.1.7.
diff --git a/pom.xml b/pom.xml
index 6765dfa..87dc6c6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,10 +5,10 @@
<artifactId>sejda-commons</artifactId>
<packaging>jar</packaging>
<name>sejda-commons</name>
- <version>1.1.7</version>
+ <version>2.0.0</version>
<description>A collection of utilities and common classes.</description>
- <url>http://www.sejda.org</url>
+ <url>https://www.sejda.org</url>
<issueManagement>
<system>GitHub</system>
@@ -17,7 +17,7 @@
<organization>
<name>sejda</name>
- <url>http://www.sejda.org</url>
+ <url>https://www.sejda.org</url>
</organization>
<licenses>
@@ -37,7 +37,7 @@
<connection>scm:git:git@github.com:torakiki/sejda-commons.git</connection>
<developerConnection>scm:git:git@github.com:torakiki/sejda-commons.git</developerConnection>
<url>scm:git:git@github.com:torakiki/sejda-commons.git</url>
- <tag>v1.1.7</tag>
+ <tag>v2.0.0</tag>
</scm>
<developers>
@@ -78,7 +78,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
- <version>3.0.0</version>
+ <version>3.1.0</version>
<executions>
<execution>
<goals>
@@ -89,7 +89,7 @@
<configuration>
<toolchains>
<jdk>
- <version>8</version>
+ <version>17</version>
</jdk>
</toolchains>
</configuration>
@@ -104,7 +104,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
- <version>3.0.1</version>
+ <version>3.4.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
@@ -122,7 +122,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
- <version>2.5.3</version>
+ <version>3.0.0-M5</version>
<configuration>
<tagNameFormat>v@{project.version}</tagNameFormat>
<preparationGoals>clean install</preparationGoals>
@@ -131,7 +131,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
- <version>1.6</version>
+ <version>3.0.1</version>
<executions>
<execution>
<id>sign-artifacts</id>
@@ -163,16 +163,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
- <version>3.8.1</version>
+ <version>3.10.1</version>
<configuration>
- <source>1.8</source>
- <target>1.8</target>
+ <release>17</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
- <version>3.1.2</version>
+ <version>3.2.2</version>
<configuration>
<archive>
<manifestEntries>
@@ -184,7 +183,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
- <version>3.1.0</version>
+ <version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
@@ -197,7 +196,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
- <version>3.0.0-M3</version>
+ <version>3.0.0-M7</version>
</plugin>
</plugins>
</build>
@@ -205,38 +204,37 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
- <version>1.7.28</version>
+ <version>1.7.36</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
- <version>1.2.3</version>
+ <version>1.2.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
- <version>1.2.3</version>
+ <version>1.2.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
- <version>3.0.0</version>
+ <version>4.6.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
- <version>5.5.1</version>
+ <version>5.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
- <version>2.1</version>
+ <version>2.2</version>
<scope>test</scope>
</dependency>
</dependencies>
-
</project>
diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java
new file mode 100644
index 0000000..6bcb4a1
--- /dev/null
+++ b/src/main/java/module-info.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2022 Sober Lemur S.a.s. di Vacondio Andrea and Sejda BV
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+module org.sejda.commons {
+ exports org.sejda.commons.collection;
+ exports org.sejda.commons.util;
+ exports org.sejda.commons;
+ requires org.slf4j;
+}
\ No newline at end of file
diff --git a/src/main/java/org/sejda/commons/Either.java b/src/main/java/org/sejda/commons/Either.java
index c4c110d..827c670 100644
--- a/src/main/java/org/sejda/commons/Either.java
+++ b/src/main/java/org/sejda/commons/Either.java
@@ -21,7 +21,7 @@ import java.util.function.Function;
/**
*
* @author Andrea Vacondio
- * @see https://stackoverflow.com/questions/48143268/java-tagged-union-sum-types
+ * @see <a href="https://stackoverflow.com/questions/48143268/java-tagged-union-sum-types">Union types</a>
*/
public abstract class Either<A, B> {
@@ -32,7 +32,7 @@ public abstract class Either<A, B> {
public abstract <C> C either(Function<? super A, ? extends C> left, Function<? super B, ? extends C> right);
public static <A, B> Either<A, B> left(A value) {
- return new Either<A, B>() {
+ return new Either<>() {
@Override
public <C> C either(Function<? super A, ? extends C> left, Function<? super B, ? extends C> right) {
return left.apply(value);
@@ -41,7 +41,7 @@ public abstract class Either<A, B> {
}
public static <A, B> Either<A, B> right(B value) {
- return new Either<A, B>() {
+ return new Either<>() {
@Override
public <C> C either(Function<? super A, ? extends C> left, Function<? super B, ? extends C> right) {
return right.apply(value);
diff --git a/src/main/java/org/sejda/commons/FastByteArrayOutputStream.java b/src/main/java/org/sejda/commons/FastByteArrayOutputStream.java
index d812095..c2c6b1c 100644
--- a/src/main/java/org/sejda/commons/FastByteArrayOutputStream.java
+++ b/src/main/java/org/sejda/commons/FastByteArrayOutputStream.java
@@ -379,10 +379,6 @@ public class FastByteArrayOutputStream extends OutputStream {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return 0;
- } else if (len < 0) {
- throw new IllegalArgumentException("len must be 0 or greater: " + len);
- } else if (off < 0) {
- throw new IllegalArgumentException("off must be 0 or greater: " + off);
} else {
if (this.currentBuffer == null) {
// This stream doesn't have any data in it...
@@ -413,7 +409,7 @@ public class FastByteArrayOutputStream extends OutputStream {
}
@Override
- public long skip(long n) throws IOException {
+ public long skip(long n) {
if (n > Integer.MAX_VALUE) {
throw new IllegalArgumentException("n exceeds maximum (" + Integer.MAX_VALUE + "): " + n);
} else if (n == 0) {
diff --git a/src/main/java/org/sejda/commons/LookupTable.java b/src/main/java/org/sejda/commons/LookupTable.java
index f5e0db7..3eff65d 100644
--- a/src/main/java/org/sejda/commons/LookupTable.java
+++ b/src/main/java/org/sejda/commons/LookupTable.java
@@ -30,7 +30,7 @@ import java.util.Set;
* type of the items
*/
public class LookupTable<I> {
- private Map<I, I> oldToNew = new LinkedHashMap<>();
+ private final Map<I, I> oldToNew = new LinkedHashMap<>();
/**
* Adds a lookup entry.
@@ -39,7 +39,7 @@ public class LookupTable<I> {
* @param valueItem
*/
public void addLookupEntry(I keyItem, I valueItem) {
- requireNotNullArg(keyItem, "Cannot map a null item");
+ requireNotNullArg(keyItem, "Cannot map a null key");
requireNotNullArg(valueItem, "Cannot map a null item");
oldToNew.put(keyItem, valueItem);
diff --git a/src/main/java/org/sejda/commons/Pool.java b/src/main/java/org/sejda/commons/Pool.java
index 15ca9ed..64215cd 100644
--- a/src/main/java/org/sejda/commons/Pool.java
+++ b/src/main/java/org/sejda/commons/Pool.java
@@ -34,7 +34,7 @@ public class Pool<T> {
private static final Logger LOG = LoggerFactory.getLogger(Pool.class);
private final ArrayBlockingQueue<T> pool;
- private Supplier<T> supplier;
+ private final Supplier<T> supplier;
private Optional<Consumer<T>> applyOnGive = Optional.empty();
diff --git a/src/main/java/org/sejda/commons/collection/LRUMap.java b/src/main/java/org/sejda/commons/collection/LRUMap.java
index 0928c46..a04c4e5 100644
--- a/src/main/java/org/sejda/commons/collection/LRUMap.java
+++ b/src/main/java/org/sejda/commons/collection/LRUMap.java
@@ -1,20 +1,17 @@
-/*
- * This file is part of the PDF Split And Merge source code
- * Created on 08/apr/2012
- * Copyright 2017 by Sober Lemur S.a.s. di Vacondio Andrea (info@pdfsam.org).
+/*
+ * Copyright 2022 Sober Lemur S.a.s. di Vacondio Andrea and Sejda BV
*
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.sejda.commons.collection;
@@ -32,7 +29,7 @@ import java.util.Map;
*/
public class LRUMap<K, V> extends LinkedHashMap<K, V> {
- private int maxCapacity;
+ private final int maxCapacity;
public LRUMap(int maxCapacity) {
super(maxCapacity, 0.75f, true);
diff --git a/src/main/java/org/sejda/commons/collection/ListValueMap.java b/src/main/java/org/sejda/commons/collection/ListValueMap.java
index 7b985fc..93ca7c2 100644
--- a/src/main/java/org/sejda/commons/collection/ListValueMap.java
+++ b/src/main/java/org/sejda/commons/collection/ListValueMap.java
@@ -34,7 +34,7 @@ import java.util.Map.Entry;
*/
public final class ListValueMap<K, V> {
- private Map<K, List<V>> map;
+ private final Map<K, List<V>> map;
public ListValueMap() {
map = new HashMap<>();
@@ -55,7 +55,7 @@ public final class ListValueMap<K, V> {
* @return the List with the input value added
*/
public List<V> put(K key, V value) {
- List<V> list = map.get(key);
+ var list = map.get(key);
if (list == null) {
list = new ArrayList<>();
}
diff --git a/src/main/java/org/sejda/commons/collection/NullSafeSet.java b/src/main/java/org/sejda/commons/collection/NullSafeSet.java
index 2b7dff8..de46fc7 100644
--- a/src/main/java/org/sejda/commons/collection/NullSafeSet.java
+++ b/src/main/java/org/sejda/commons/collection/NullSafeSet.java
@@ -29,7 +29,7 @@ import java.util.Set;
*/
public class NullSafeSet<E> implements Set<E> {
- private Set<E> delegate;
+ private final Set<E> delegate;
public NullSafeSet() {
delegate = new LinkedHashSet<>();
diff --git a/src/main/java/org/sejda/commons/util/IOUtils.java b/src/main/java/org/sejda/commons/util/IOUtils.java
index 05607d1..88c3d72 100644
--- a/src/main/java/org/sejda/commons/util/IOUtils.java
+++ b/src/main/java/org/sejda/commons/util/IOUtils.java
@@ -15,17 +15,19 @@
*/
package org.sejda.commons.util;
-import static java.util.Objects.nonNull;
-import static org.sejda.commons.util.RequireUtils.requireNotNullArg;
+import org.sejda.commons.FastByteArrayOutputStream;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.function.Consumer;
-import org.sejda.commons.FastByteArrayOutputStream;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import static java.util.Objects.nonNull;
+import static java.util.Optional.ofNullable;
+import static org.sejda.commons.util.RequireUtils.requireNotNullArg;
/**
* Utility class with I/O related static methods
@@ -40,8 +42,7 @@ public final class IOUtils {
/**
* Null safe close of the given {@link Closeable}.
*
- * @param closeable
- * to be closed
+ * @param closeable to be closed
* @throws IOException
*/
public static void close(Closeable closeable) throws IOException {
@@ -53,16 +54,24 @@ public final class IOUtils {
/**
* Null safe close of the given {@link Closeable} suppressing any exception.
*
- * @param closeable
- * to be closed
+ * @param closeable to be closed
*/
public static void closeQuietly(Closeable closeable) {
+ closeQuietly(closeable, null);
+ }
+
+ /**
+ * Null safe close of the given {@link Closeable} handing the potential exception to the given consumer
+ *
+ * @param closeable to be closed
+ * @param consumer consumer for the potential {@link Exception}. If null the exception is logged as a warning.
+ */
+ public static void closeQuietly(Closeable closeable, Consumer<IOException> consumer) {
try {
- if (nonNull(closeable)) {
- closeable.close();
- }
+ close(closeable);
} catch (IOException ioe) {
- LOG.warn("An error occured while closing a Closeable resource", ioe);
+ ofNullable(consumer).ifPresentOrElse(c -> c.accept(ioe),
+ () -> LOG.warn("An error occurred while closing a Closeable resource", ioe));
}
}
@@ -73,16 +82,14 @@ public final class IOUtils {
*/
public static byte[] toByteArray(InputStream input) throws IOException {
try (FastByteArrayOutputStream output = new FastByteArrayOutputStream()) {
- copy(input, output);
- // java9
- // input.transferTo(output);
+ input.transferTo(output);
return output.toByteArray();
}
}
/**
* Copy the input stream data to the output stream
- *
+ *
* @param input
* @param output
* @throws IOException
@@ -90,10 +97,6 @@ public final class IOUtils {
public static void copy(InputStream input, OutputStream output) throws IOException {
requireNotNullArg(input, "Cannot copy a null input");
requireNotNullArg(output, "Cannot copy to a null output");
- byte[] buffer = new byte[8192];
- int read;
- while ((read = input.read(buffer, 0, 8192)) >= 0) {
- output.write(buffer, 0, read);
- }
+ input.transferTo(output);
}
}
diff --git a/src/main/java/org/sejda/commons/util/NumericalSortFilenameComparator.java b/src/main/java/org/sejda/commons/util/NumericalSortFilenameComparator.java
index 10ce092..4d04717 100644
--- a/src/main/java/org/sejda/commons/util/NumericalSortFilenameComparator.java
+++ b/src/main/java/org/sejda/commons/util/NumericalSortFilenameComparator.java
@@ -38,13 +38,11 @@ import java.util.regex.Pattern;
*/
public class NumericalSortFilenameComparator implements Comparator<File> {
- private static Pattern PATTERN = Pattern.compile("^(\\d*)(.*)(\\d*)$");
+ private static final Pattern PATTERN = Pattern.compile("^(\\d*)(.*)(\\d*)$");
- private static Function<String, BigInteger> DIGITS_EXTRACTOR = (g) -> {
- return ofNullable(g).filter(StringUtils::isNotEmpty).map(BigInteger::new).orElse(null);
- };
+ private static final Function<String, BigInteger> DIGITS_EXTRACTOR = (g) -> ofNullable(g).filter(StringUtils::isNotEmpty).map(BigInteger::new).orElse(null);
- private static Comparator<String> BIG_INT_COMPARATOR = (a, b) -> {
+ private static final Comparator<String> BIG_INT_COMPARATOR = (a, b) -> {
BigInteger bigA = DIGITS_EXTRACTOR.apply(a);
BigInteger bigB = DIGITS_EXTRACTOR.apply(b);
if (nonNull(bigA) && nonNull(bigB)) {
@@ -53,7 +51,7 @@ public class NumericalSortFilenameComparator implements Comparator<File> {
return 0;
};
- private static Comparator<String> STRING_COMPARATOR = (a, b) -> {
+ private static final Comparator<String> STRING_COMPARATOR = (a, b) -> {
if (isNotEmpty(a) && isNotEmpty(b)) {
return a.compareToIgnoreCase(b);
}
@@ -74,22 +72,22 @@ public class NumericalSortFilenameComparator implements Comparator<File> {
return null;
}
- private static Comparator<Matcher> MATCHER_COMPARATOR = comparing((Matcher m) -> m.group(1), BIG_INT_COMPARATOR)
- .thenComparing(comparing(m -> m.group(2), STRING_COMPARATOR))
- .thenComparing(comparing(m -> m.group(3), BIG_INT_COMPARATOR));
+ private static final Comparator<Matcher> MATCHER_COMPARATOR = comparing((Matcher m) -> m.group(1), BIG_INT_COMPARATOR)
+ .thenComparing(m -> m.group(2), STRING_COMPARATOR)
+ .thenComparing(m -> m.group(3), BIG_INT_COMPARATOR);
- private Comparator<File> fallback;
+ private final Comparator<File> fallback;
/**
* @param fallback
- * the comparator to use when numerical sorting fails. Default is file name case insensitive compare
+ * the comparator to use when numerical sorting fails. Default is file name case-insensitive compare
*/
public NumericalSortFilenameComparator(Comparator<File> fallback) {
this.fallback = ofNullable(fallback).orElse(nullsLast(comparing(File::getName, String.CASE_INSENSITIVE_ORDER)));
}
/**
- * Comparator performing numerical sort with fallback to file name case insensitive compare in case numerical sort fails
+ * Comparator performing numerical sort with fallback to file name case-insensitive compare in case numerical sort fails
*/
public NumericalSortFilenameComparator() {
this(null);
diff --git a/src/main/java/org/sejda/commons/util/ReflectionUtils.java b/src/main/java/org/sejda/commons/util/ReflectionUtils.java
index 16a9da6..c12031b 100644
--- a/src/main/java/org/sejda/commons/util/ReflectionUtils.java
+++ b/src/main/java/org/sejda/commons/util/ReflectionUtils.java
@@ -24,7 +24,7 @@ import java.lang.reflect.UndeclaredThrowableException;
/**
* Simple utility class for working with the reflection API and handling reflection exceptions.
- *
+ * <p>
* From Springframework
*
*/
@@ -143,11 +143,11 @@ public final class ReflectionUtils {
* the rethrown exception
*/
public static void rethrowRuntimeException(Throwable ex) {
- if (ex instanceof RuntimeException) {
- throw (RuntimeException) ex;
+ if (ex instanceof RuntimeException re) {
+ throw re;
}
- if (ex instanceof Error) {
- throw (Error) ex;
+ if (ex instanceof Error e) {
+ throw e;
}
throw new UndeclaredThrowableException(ex);
}
@@ -162,8 +162,8 @@ public final class ReflectionUtils {
*/
public static void makeAccessible(Field field) {
if ((!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic(field.getDeclaringClass().getModifiers())
- || Modifier.isFinal(field.getModifiers())) && !field.isAccessible()) {
- field.setAccessible(true);
+ || Modifier.isFinal(field.getModifiers()))) {
+ field.trySetAccessible();
}
}
diff --git a/src/main/java/org/sejda/commons/util/StringUtils.java b/src/main/java/org/sejda/commons/util/StringUtils.java
index 1f84388..3e4bfdc 100644
--- a/src/main/java/org/sejda/commons/util/StringUtils.java
+++ b/src/main/java/org/sejda/commons/util/StringUtils.java
@@ -51,7 +51,7 @@ public class StringUtils {
public static String asUnicodes(String in) {
if (nonNull(in)) {
- StringBuilder result = new StringBuilder();
+ var result = new StringBuilder();
for (int offset = 0; offset < in.length();) {
int codepoint = in.codePointAt(offset);
result.append("\\U+").append(Integer.toHexString(codepoint).toUpperCase());
@@ -69,4 +69,8 @@ public class StringUtils {
public static boolean isNotEmpty(final CharSequence cs) {
return !isEmpty(cs);
}
+
+ public static String normalizeLineEndings(String in) {
+ return in.replaceAll("\\r\\n", "\n");
+ }
}
diff --git a/src/test/java/org/sejda/commons/collection/LRUMapTest.java b/src/test/java/org/sejda/commons/collection/LRUMapTest.java
index c33529f..b12c4d0 100644
--- a/src/test/java/org/sejda/commons/collection/LRUMapTest.java
+++ b/src/test/java/org/sejda/commons/collection/LRUMapTest.java
@@ -1,29 +1,26 @@
-/*
- * This file is part of the PDF Split And Merge source code
- * Created on 08/apr/2012
- * Copyright 2017 by Sober Lemur S.a.s. di Vacondio Andrea (info@pdfsam.org).
+/*
+ * Copyright 2022 Sober Lemur S.a.s. di Vacondio Andrea and Sejda BV
*
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.sejda.commons.collection;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import org.junit.jupiter.api.Test;
import java.util.Map;
-import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
/**
* @author Andrea Vacondio
@@ -36,9 +33,9 @@ public class LRUMapTest {
Map<String, String> victim = new LRUMap<>(2);
victim.put("1", "A");
victim.put("2", "B");
- assertTrue(victim.size() == 2);
+ assertEquals(2, victim.size());
victim.put("3", "C");
- assertTrue(victim.size() == 2);
+ assertEquals(2, victim.size());
assertFalse(victim.containsKey("1"));
}
}
diff --git a/src/test/java/org/sejda/commons/util/IOUtilsTest.java b/src/test/java/org/sejda/commons/util/IOUtilsTest.java
index fb84e64..b53ac1d 100644
--- a/src/test/java/org/sejda/commons/util/IOUtilsTest.java
+++ b/src/test/java/org/sejda/commons/util/IOUtilsTest.java
@@ -15,33 +15,37 @@
*/
package org.sejda.commons.util;
-import static org.junit.jupiter.api.Assertions.assertArrayEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
import java.io.IOException;
+import java.util.function.Consumer;
-import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
/**
* @author Andrea Vacondio
- *
*/
public class IOUtilsTest {
@Test
public void copyNullInput() {
- assertThrows(IllegalArgumentException.class, () -> {
- IOUtils.copy(null, new ByteArrayOutputStream());
- }, "Cannot copy a null input");
+ assertThrows(IllegalArgumentException.class, () -> IOUtils.copy(null, new ByteArrayOutputStream()),
+ "Cannot copy a null input");
}
@Test
public void copyNullOutput() {
- assertThrows(IllegalArgumentException.class, () -> {
- IOUtils.copy(new ByteArrayInputStream(new byte[1]), null);
- }, "Cannot copy to a null output");
+ assertThrows(IllegalArgumentException.class, () -> IOUtils.copy(new ByteArrayInputStream(new byte[1]), null),
+ "Cannot copy to a null output");
}
@Test
@@ -57,4 +61,43 @@ public class IOUtilsTest {
byte[] data = { '3', '5' };
assertArrayEquals(data, IOUtils.toByteArray(new ByteArrayInputStream(data)));
}
+
+ @Test
+ void closeCloseable() throws IOException {
+ Closeable closeable = mock(Closeable.class);
+ IOUtils.close(closeable);
+ verify(closeable).close();
+ }
+
+ @Test
+ @DisplayName("Closing null doesn't throw")
+ void closeQuietlyNull() {
+ IOUtils.closeQuietly(null);
+ }
+
+ @Test
+ void closeQuietly() throws IOException {
+ Closeable closeable = mock(Closeable.class);
+ IOUtils.closeQuietly(closeable);
+ verify(closeable).close();
+ }
+
+ @Test
+ @DisplayName("Closing exception doesn't rethrow")
+ void closeQuietlyException() throws IOException {
+ Closeable closeable = mock(Closeable.class);
+ doThrow(new IOException()).when(closeable).close();
+ IOUtils.closeQuietly(closeable);
+ verify(closeable).close();
+ }
+
+ @Test
+ void closeQuietlyConsumer() throws IOException {
+ Closeable closeable = mock(Closeable.class);
+ doThrow(new IOException()).when(closeable).close();
+ Consumer<IOException> consumer = mock(Consumer.class);
+ IOUtils.closeQuietly(closeable, consumer);
+ verify(closeable).close();
+ verify(consumer).accept(any());
+ }
}
Debdiff
[The following lists of changes regard files as different if they have different names, permissions or owners.]
Files in second set of .debs but not in first
-rw-r--r-- root/root /usr/share/maven-repo/org/sejda/sejda-commons/2.0.0/sejda-commons-2.0.0.pom lrwxrwxrwx root/root /usr/share/java/sejda-commons-2.0.0.jar -> sejda-commons.jar lrwxrwxrwx root/root /usr/share/maven-repo/org/sejda/sejda-commons/2.0.0/sejda-commons-2.0.0.jar -> ../../../../../java/sejda-commons.jar
Files in first set of .debs but not in second
-rw-r--r-- root/root /usr/share/maven-repo/org/sejda/sejda-commons/1.1.7/sejda-commons-1.1.7.pom lrwxrwxrwx root/root /usr/share/java/sejda-commons-1.1.7.jar -> sejda-commons.jar lrwxrwxrwx root/root /usr/share/maven-repo/org/sejda/sejda-commons/1.1.7/sejda-commons-1.1.7.jar -> ../../../../../java/sejda-commons.jar
No differences were encountered in the control files