Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dev-support/pmd/pmd-ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
PMD Ruleset for Apache Ozone
</description>

<rule ref="category/java/bestpractices.xml/AvoidStringBufferField" />
<rule ref="category/java/bestpractices.xml/ForLoopCanBeForeach"/>
<rule ref="category/java/bestpractices.xml/MissingOverride"/>
<rule ref="category/java/bestpractices.xml/UnusedPrivateMethod"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class DirstreamClientHandler extends ChannelInboundHandlerAdapter {

private final StreamingDestination destination;
private boolean headerMode = true;
private StringBuilder currentFileName = new StringBuilder();
private String currentFileName = "";
private RandomAccessFile destFile;

private FileChannel destFileChannel;
Expand Down Expand Up @@ -76,11 +76,10 @@ public void doRead(ChannelHandlerContext ctx, ByteBuf buffer)
if (eolPosition > 0) {
headerMode = false;
final ByteBuf name = buffer.readBytes(eolPosition);
currentFileName.append(name
.toString(StandardCharsets.UTF_8));
currentFileName += name.toString(StandardCharsets.UTF_8);
name.release();
buffer.skipBytes(1);
String[] parts = currentFileName.toString().split(" ", 2);
String[] parts = currentFileName.split(" ", 2);
remaining = Long.parseLong(parts[0]);
Path destFilePath = destination.mapToDestination(parts[1]);
final Path destfileParent = destFilePath.getParent();
Expand All @@ -94,8 +93,7 @@ public void doRead(ChannelHandlerContext ctx, ByteBuf buffer)
destFileChannel = this.destFile.getChannel();

} else {
currentFileName
.append(buffer.toString(StandardCharsets.UTF_8));
currentFileName += buffer.toString(StandardCharsets.UTF_8);
}
}
if (!headerMode) {
Expand All @@ -105,7 +103,7 @@ public void doRead(ChannelHandlerContext ctx, ByteBuf buffer)
buffer.readBytes(destFileChannel, readableBytes);
} else {
remaining -= buffer.readBytes(destFileChannel, (int) remaining);
currentFileName = new StringBuilder();
currentFileName = "";
headerMode = true;
destFile.close();
if (readableBytes > 0) {
Expand Down Expand Up @@ -142,6 +140,6 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
}

public String getCurrentFileName() {
return currentFileName.toString();
return currentFileName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public class DirstreamServerHandler extends ChannelInboundHandlerAdapter {

public static final String END_MARKER = "0 END";

private final StringBuilder id = new StringBuilder();

private StreamingSource source;

private boolean headerProcessed = false;
Expand All @@ -59,6 +57,7 @@ public DirstreamServerHandler(StreamingSource source) {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg)
throws Exception {
StringBuilder id = new StringBuilder();
if (!headerProcessed) {
ByteBuf buffer = (ByteBuf) msg;
int eolPosition = buffer.forEachByte(ByteProcessor.FIND_LF) - buffer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ private String getLowerCaseOp(String op) {
/**
* Utility class for building performance log strings.
*/
@SuppressWarnings(value = "PMD.AvoidStringBufferField")
public static class PerformanceStringBuilder {
private final StringBuilder builder = new StringBuilder(128).append('{');
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public class TestOmRatisSnapshotProvider {
"Content-Disposition: form-data; name=\""
+ OzoneConsts.OZONE_DB_CHECKPOINT_REQUEST_TO_EXCLUDE_SST + "[]\""
+ CR_NL + CR_NL;
private StringBuilder sb;
private File targetFile;

@BeforeEach
Expand All @@ -79,16 +78,13 @@ public void setup(@TempDir File snapshotDir,
omRatisSnapshotProvider =
new OmRatisSnapshotProvider(snapshotDir, peerNodesMap, httpPolicy,
false, connectionFactory);

sb = new StringBuilder();
sb.append("--").append(MULTIPART_FORM_DATA_BOUNDARY).append(CR_NL);
sb.append(CONTENT_DISPOSITION);
}

@Test
public void testDownloadSnapshot() throws IOException,
AuthenticationException {
URL omCheckpointUrl = mock(URL.class);
StringBuilder sb = getStringBuilder();
when(leader.getOMDBCheckpointEndpointUrl(anyBoolean(), anyBoolean()))
.thenReturn(omCheckpointUrl);

Expand Down Expand Up @@ -117,6 +113,7 @@ public void testWriteFormDataWithSstFile() throws IOException {
String fileName = "file1.sst";
sstFiles.add(fileName);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
StringBuilder sb = getStringBuilder();
when(connection.getOutputStream()).thenReturn(outputStream);


Expand All @@ -132,6 +129,7 @@ public void testWriteFormDataWithSstFile() throws IOException {
public void testWriteFormDataWithoutSstFile() throws IOException {
HttpURLConnection connection = mock(HttpURLConnection.class);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
StringBuilder sb = getStringBuilder();
when(connection.getOutputStream()).thenReturn(outputStream);

OmRatisSnapshotProvider.writeFormData(connection, new ArrayList<>());
Expand All @@ -141,4 +139,11 @@ public void testWriteFormDataWithoutSstFile() throws IOException {
new String(outputStream.toByteArray(), StandardCharsets.UTF_8));
}

private static StringBuilder getStringBuilder() {
StringBuilder sb = new StringBuilder();
sb.append("--").append(MULTIPART_FORM_DATA_BOUNDARY).append(CR_NL);
sb.append(CONTENT_DISPOSITION);
return sb;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,13 @@ public class DiskUsageSubCommand implements Callable {
private static final int DU_INDENT = 12;
private static final int PATH_INDENT = 27;

private StringBuffer url = new StringBuffer();

@Override
public Void call() throws Exception {
if (path == null || path.isEmpty()) {
printEmptyPathRequest();
return null;
}
StringBuilder url = new StringBuilder();
url.append(parent.getReconWebAddress()).append(ENDPOINT);

String response = makeHttpCall(url, parseInputPath(path), listFiles,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@ public class FileSizeDistSubCommand implements Callable {

private static final String ENDPOINT = "/api/v1/namespace/dist";

private StringBuffer url = new StringBuffer();

@Override
public Void call() throws Exception {
if (path == null || path.isEmpty()) {
printEmptyPathRequest();
return null;
}
StringBuilder url = new StringBuilder();
url.append(parent.getReconWebAddress()).append(ENDPOINT);

printNewLines(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ private NSSummaryCLIUtils() {

private static final String OFS_PREFIX = "ofs://";

public static String makeHttpCall(StringBuffer url, String path,
public static String makeHttpCall(StringBuilder url, String path,
boolean isSpnegoEnabled,
ConfigurationSource conf)
throws Exception {
return makeHttpCall(url, path, false, false, isSpnegoEnabled, conf);
}

public static String makeHttpCall(StringBuffer url, String path,
public static String makeHttpCall(StringBuilder url, String path,
boolean listFile, boolean withReplica,
boolean isSpnegoEnabled,
ConfigurationSource conf)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,13 @@ public class QuotaUsageSubCommand implements Callable {

private static final String ENDPOINT = "/api/v1/namespace/quota";

private StringBuffer url = new StringBuffer();

@Override
public Void call() throws Exception {
if (path == null || path.isEmpty()) {
printEmptyPathRequest();
return null;
}
StringBuilder url = new StringBuilder();
url.append(parent.getReconWebAddress()).append(ENDPOINT);

printNewLines(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@ public class SummarySubCommand implements Callable<Void> {

private static final String ENDPOINT = "/api/v1/namespace/summary";

private StringBuffer url = new StringBuffer();

@Override
public Void call() throws Exception {
if (path == null || path.isEmpty()) {
printEmptyPathRequest();
return null;
}
StringBuilder url = new StringBuilder();
url.append(parent.getReconWebAddress()).append(ENDPOINT);

printNewLines(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* | bigdata-ozone-online31 | om31 | LEADER |
* +---------------------------------+---------+----------+
*/
@SuppressWarnings(value = "PMD.AvoidStringBufferField")
public final class FormattingCLIUtils {
/** Table title. */
private String title;
Expand Down