This is an automated email from the ASF dual-hosted git repository.
pvillard pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new b80a673ab8 NIFI-14138 Replaced deprecated
com.google.common.base.Charsets with Java 21 equivalent
java.nio.charset.StandardCharsets
b80a673ab8 is described below
commit b80a673ab8868d9ba62e1214c622ef9264a19109
Author: dan-s1 <[email protected]>
AuthorDate: Wed Jan 8 22:46:23 2025 +0000
NIFI-14138 Replaced deprecated com.google.common.base.Charsets with Java 21
equivalent java.nio.charset.StandardCharsets
Signed-off-by: Pierre Villard <[email protected]>
This closes #9615.
---
.../nifi/processors/evtx/parser/BinaryReaderTest.java | 16 ++++++++--------
.../processors/evtx/parser/TestBinaryReaderBuilder.java | 6 +++---
.../evtx/parser/bxml/value/BinaryTypeNodeTest.java | 9 +++++----
.../processors/parquet/TestConvertAvroToParquet.java | 4 ++--
4 files changed, 18 insertions(+), 17 deletions(-)
diff --git
a/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/BinaryReaderTest.java
b/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/BinaryReaderTest.java
index b5a794a4dc..13300e052e 100644
---
a/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/BinaryReaderTest.java
+++
b/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/BinaryReaderTest.java
@@ -17,7 +17,6 @@
package org.apache.nifi.processors.evtx.parser;
-import com.google.common.base.Charsets;
import com.google.common.primitives.UnsignedInteger;
import com.google.common.primitives.UnsignedLong;
import org.junit.jupiter.api.BeforeEach;
@@ -25,6 +24,7 @@ import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Base64;
import java.util.Date;
@@ -59,7 +59,7 @@ public class BinaryReaderTest {
@Test
public void testReadBytesJustLength() throws IOException {
- byte[] bytes = "Hello world".getBytes(Charsets.US_ASCII);
+ byte[] bytes = "Hello world".getBytes(StandardCharsets.US_ASCII);
BinaryReader binaryReader = testBinaryReaderBuilder.put(bytes).build();
assertArrayEquals(Arrays.copyOfRange(bytes, 0, 5),
binaryReader.readBytes(5));
assertEquals(5, binaryReader.getPosition());
@@ -67,7 +67,7 @@ public class BinaryReaderTest {
@Test
public void testPeekBytes() throws IOException {
- byte[] bytes = "Hello world".getBytes(Charsets.US_ASCII);
+ byte[] bytes = "Hello world".getBytes(StandardCharsets.US_ASCII);
BinaryReader binaryReader = testBinaryReaderBuilder.put(bytes).build();
assertArrayEquals(Arrays.copyOfRange(bytes, 0, 5),
binaryReader.peekBytes(5));
assertEquals(0, binaryReader.getPosition());
@@ -75,7 +75,7 @@ public class BinaryReaderTest {
@Test
public void testReadBytesBufOffsetLength() throws IOException {
- byte[] bytes = "Hello world".getBytes(Charsets.US_ASCII);
+ byte[] bytes = "Hello world".getBytes(StandardCharsets.US_ASCII);
byte[] buf = new byte[5];
BinaryReader binaryReader = testBinaryReaderBuilder.put(bytes).build();
@@ -96,7 +96,7 @@ public class BinaryReaderTest {
public void testReadStringNotNullTerminated() throws IOException {
String value = "Hello world";
- BinaryReader binaryReader =
testBinaryReaderBuilder.put(value.getBytes(Charsets.US_ASCII)).build();
+ BinaryReader binaryReader =
testBinaryReaderBuilder.put(value.getBytes(StandardCharsets.US_ASCII)).build();
assertThrows(IOException.class, () ->
binaryReader.readString(value.length()));
}
@@ -175,7 +175,7 @@ public class BinaryReaderTest {
@Test
public void testReadAndBase64EncodeBinary() throws IOException {
String orig = "Hello World";
- String stringValue =
Base64.getEncoder().encodeToString(orig.getBytes(Charsets.US_ASCII));
+ String stringValue =
Base64.getEncoder().encodeToString(orig.getBytes(StandardCharsets.US_ASCII));
BinaryReader binaryReader =
testBinaryReaderBuilder.putBase64EncodedBinary(stringValue).build();
assertEquals(stringValue,
binaryReader.readAndBase64EncodeBinary(orig.length()));
@@ -192,7 +192,7 @@ public class BinaryReaderTest {
@Test
public void testReaderPositionConstructor() throws IOException {
String value = "Hello world";
- BinaryReader binaryReader = new BinaryReader(new
BinaryReader(value.getBytes(Charsets.UTF_16LE)), 2);
+ BinaryReader binaryReader = new BinaryReader(new
BinaryReader(value.getBytes(StandardCharsets.UTF_16LE)), 2);
assertEquals(value.substring(1),
binaryReader.readWString(value.length() - 1));
assertEquals(value.length() * 2, binaryReader.getPosition());
@@ -201,7 +201,7 @@ public class BinaryReaderTest {
@Test
public void testInputStreamSizeConstructor() throws IOException {
String value = "Hello world";
- BinaryReader binaryReader = new BinaryReader(new
ByteArrayInputStream(value.getBytes(Charsets.UTF_16LE)), 10);
+ BinaryReader binaryReader = new BinaryReader(new
ByteArrayInputStream(value.getBytes(StandardCharsets.UTF_16LE)), 10);
assertEquals(value.substring(0, 5), binaryReader.readWString(5));
assertEquals(10, binaryReader.getPosition());
diff --git
a/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/TestBinaryReaderBuilder.java
b/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/TestBinaryReaderBuilder.java
index 8230fa4aca..c03d63623b 100644
---
a/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/TestBinaryReaderBuilder.java
+++
b/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/TestBinaryReaderBuilder.java
@@ -17,7 +17,6 @@
package org.apache.nifi.processors.evtx.parser;
-import com.google.common.base.Charsets;
import com.google.common.primitives.UnsignedInteger;
import com.google.common.primitives.UnsignedLong;
@@ -25,6 +24,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Calendar;
@@ -63,13 +63,13 @@ public class TestBinaryReaderBuilder {
}
public TestBinaryReaderBuilder putString(String val) {
- data.add(val.getBytes(Charsets.US_ASCII));
+ data.add(val.getBytes(StandardCharsets.US_ASCII));
data.add(new byte[]{0});
return this;
}
public TestBinaryReaderBuilder putWString(String val) {
- data.add(val.getBytes(Charsets.UTF_16LE));
+ data.add(val.getBytes(StandardCharsets.UTF_16LE));
return this;
}
diff --git
a/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/bxml/value/BinaryTypeNodeTest.java
b/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/bxml/value/BinaryTypeNodeTest.java
index b38882de12..c7043e246d 100644
---
a/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/bxml/value/BinaryTypeNodeTest.java
+++
b/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/bxml/value/BinaryTypeNodeTest.java
@@ -17,13 +17,13 @@
package org.apache.nifi.processors.evtx.parser.bxml.value;
-import com.google.common.base.Charsets;
import com.google.common.primitives.UnsignedInteger;
import org.apache.nifi.processors.evtx.parser.BinaryReader;
import org.apache.nifi.processors.evtx.parser.bxml.BxmlNodeTestBase;
import org.junit.jupiter.api.Test;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.Base64;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -34,20 +34,21 @@ public class BinaryTypeNodeTest extends BxmlNodeTestBase {
public void testLength() throws IOException {
String val = "Test String";
BinaryReader binaryReader =
testBinaryReaderBuilder.putDWord(val.length()).putString(val).build();
-
assertEquals(Base64.getEncoder().encodeToString(val.getBytes(Charsets.US_ASCII)),
new BinaryTypeNode(binaryReader, chunkHeader, parent, -1).getValue());
+
assertEquals(Base64.getEncoder().encodeToString(val.getBytes(StandardCharsets.US_ASCII)),
new BinaryTypeNode(binaryReader, chunkHeader, parent, -1).getValue());
}
@Test
public void testInvalidStringLength() throws IOException {
String val = "Test String";
BinaryReader binaryReader =
testBinaryReaderBuilder.putDWord(UnsignedInteger.fromIntBits(Integer.MAX_VALUE
+ 1)).putString(val).build();
- assertThrows(IOException.class, () ->
assertEquals(Base64.getEncoder().encodeToString(val.getBytes(Charsets.US_ASCII)),
new BinaryTypeNode(binaryReader, chunkHeader, parent, -1).getValue()));
+ assertThrows(IOException.class,
+ () ->
assertEquals(Base64.getEncoder().encodeToString(val.getBytes(StandardCharsets.US_ASCII)),
new BinaryTypeNode(binaryReader, chunkHeader, parent, -1).getValue()));
}
@Test
public void testNoLength() throws IOException {
String val = "Test String";
BinaryReader binaryReader =
testBinaryReaderBuilder.putString(val).build();
-
assertEquals(Base64.getEncoder().encodeToString(val.getBytes(Charsets.US_ASCII)),
new BinaryTypeNode(binaryReader, chunkHeader, parent,
val.length()).getValue());
+
assertEquals(Base64.getEncoder().encodeToString(val.getBytes(StandardCharsets.US_ASCII)),
new BinaryTypeNode(binaryReader, chunkHeader, parent,
val.length()).getValue());
}
}
diff --git
a/nifi-extension-bundles/nifi-parquet-bundle/nifi-parquet-processors/src/test/java/org/apache/nifi/processors/parquet/TestConvertAvroToParquet.java
b/nifi-extension-bundles/nifi-parquet-bundle/nifi-parquet-processors/src/test/java/org/apache/nifi/processors/parquet/TestConvertAvroToParquet.java
index c30443ab26..c3508b7c16 100644
---
a/nifi-extension-bundles/nifi-parquet-bundle/nifi-parquet-processors/src/test/java/org/apache/nifi/processors/parquet/TestConvertAvroToParquet.java
+++
b/nifi-extension-bundles/nifi-parquet-bundle/nifi-parquet-processors/src/test/java/org/apache/nifi/processors/parquet/TestConvertAvroToParquet.java
@@ -16,13 +16,13 @@
*/
package org.apache.nifi.processors.parquet;
-import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableMap;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -91,7 +91,7 @@ public class TestConvertAvroToParquet {
.set("mylong", 2L)
.set("myfloat", 3.1f)
.set("mydouble", 4.1)
- .set("mybytes",
ByteBuffer.wrap("hello".getBytes(Charsets.UTF_8)))
+ .set("mybytes",
ByteBuffer.wrap("hello".getBytes(StandardCharsets.UTF_8)))
.set("mystring", "hello")
.set("mynestedrecord", nestedRecord)
.set("myarray", new
GenericData.Array<>(Schema.createArray(Schema.create(Schema.Type.INT)),
Arrays.asList(1, 2)))