Skip to content

Commit

Permalink
GH-39752: [Java] Remove Static imports for Utf8 Usage (#40683)
Browse files Browse the repository at this point in the history
### What changes are included in this PR?

Removing static imports of UTF_8. This has been identified as a minor enhancement as documented here: #39752 and discussed in a review [here](#39529 (comment)). 

### Are these changes tested?

Tested by existing test cases. 

### Are there any user-facing changes?

No
* GitHub Issue: #39752

Authored-by: Vibhatha Abeykoon <vibhatha@gmail.com>
Signed-off-by: David Li <li.davidm96@gmail.com>
  • Loading branch information
vibhatha authored Mar 20, 2024
1 parent b8e5b51 commit 3e9b94f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
package org.apache.arrow.driver.jdbc.accessor.impl.text;

import static java.nio.charset.StandardCharsets.US_ASCII;
import static java.nio.charset.StandardCharsets.UTF_8;

import java.io.ByteArrayInputStream;
import java.io.CharArrayReader;
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.sql.Date;
import java.sql.SQLException;
import java.sql.Time;
Expand Down Expand Up @@ -81,7 +81,7 @@ public Class<?> getObjectClass() {
@Override
public String getObject() {
final byte[] bytes = getBytes();
return bytes == null ? null : new String(bytes, UTF_8);
return bytes == null ? null : new String(bytes, StandardCharsets.UTF_8);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static com.google.protobuf.Any.pack;
import static com.google.protobuf.ByteString.copyFrom;
import static java.lang.String.format;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Collections.singletonList;
import static java.util.Objects.isNull;
import static java.util.UUID.randomUUID;
Expand All @@ -43,6 +42,7 @@
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
Expand Down Expand Up @@ -428,7 +428,7 @@ private static <T extends FieldVector> int saveToVectors(final Map<T, String> ve

range(0, split.length)
.forEach(i -> {
byte[] bytes = split[i].getBytes(UTF_8);
byte[] bytes = split[i].getBytes(StandardCharsets.UTF_8);
Preconditions.checkState(bytes.length < 1024,
"The amount of bytes is greater than what the ArrowBuf supports");
buf.setBytes(0, bytes);
Expand Down Expand Up @@ -701,7 +701,7 @@ public void closePreparedStatement(final ActionClosePreparedStatementRequest req
@Override
public FlightInfo getFlightInfoStatement(final CommandStatementQuery request, final CallContext context,
final FlightDescriptor descriptor) {
ByteString handle = copyFrom(randomUUID().toString().getBytes(UTF_8));
ByteString handle = copyFrom(randomUUID().toString().getBytes(StandardCharsets.UTF_8));

try {
// Ownership of the connection will be passed to the context. Do NOT close!
Expand Down Expand Up @@ -778,7 +778,7 @@ public void createPreparedStatement(final ActionCreatePreparedStatementRequest r
// Running on another thread
Future<?> unused = executorService.submit(() -> {
try {
final ByteString preparedStatementHandle = copyFrom(randomUUID().toString().getBytes(UTF_8));
final ByteString preparedStatementHandle = copyFrom(randomUUID().toString().getBytes(StandardCharsets.UTF_8));
// Ownership of the connection will be passed to the context. Do NOT close!
final Connection connection = dataSource.getConnection();
final PreparedStatement preparedStatement = connection.prepareStatement(request.getQuery(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static com.fasterxml.jackson.core.JsonToken.END_OBJECT;
import static com.fasterxml.jackson.core.JsonToken.START_ARRAY;
import static com.fasterxml.jackson.core.JsonToken.START_OBJECT;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.arrow.vector.BufferLayout.BufferType.DATA;
import static org.apache.arrow.vector.BufferLayout.BufferType.OFFSET;
import static org.apache.arrow.vector.BufferLayout.BufferType.TYPE;
Expand All @@ -31,6 +30,7 @@
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -538,7 +538,7 @@ ArrowBuf readStringValues(
long bufferSize = 0L;
for (int i = 0; i < count; i++) {
parser.nextToken();
final byte[] value = parser.getValueAsString().getBytes(UTF_8);
final byte[] value = parser.getValueAsString().getBytes(StandardCharsets.UTF_8);
values.add(value);
bufferSize += value.length;
}
Expand Down

0 comments on commit 3e9b94f

Please sign in to comment.