PMD fixes

Signed-off-by: Leo Galambos <lg@hq.egothor.org>
This commit is contained in:
2025-07-30 22:18:53 +02:00
parent cc05287189
commit 62d2947142
3 changed files with 31 additions and 18 deletions

View File

@@ -71,6 +71,13 @@ abstract class AbstractExportableDataContent implements ExportableDataContent {
*/
protected DataContent input;
/**
* Default constructor.
*/
public AbstractExportableDataContent() {
// empty
}
/**
* Sets the input {@link DataContent} for export.
*

View File

@@ -94,12 +94,20 @@ import java.util.Base64.Encoder;
*/
public class Base64Stream extends InputStream {
InputStream source;
InputStream in, prefix, suffix;
Encoder base64;
int pos = 0;
final int lineLength;
int lineBreak;
private final InputStream source;
private InputStream in;
private InputStream prefix;
private InputStream suffix;
private final Encoder base64;
private int pos;
private final int lineLength;
private int lineBreak;
private InputStream is = nullInputStream(); // NOPMD
private int breakPos; // NOPMD
private boolean closed;
private final static int TRIPLES_INPUT = 1000;
/**
* Constructs a new {@code Base64Stream}.
@@ -113,9 +121,11 @@ public class Base64Stream extends InputStream {
* newline); can be {@code null}
*/
public Base64Stream(InputStream source, byte[] linePrefix, int lineLength, byte[] lineSuffix) {
super();
this.source = source;
this.lineLength = lineLength;
in = InputStream.nullInputStream();
in = nullInputStream();
base64 = Base64.getEncoder();
if (linePrefix != null) {
prefix = new ByteArrayInputStream(linePrefix);
@@ -133,10 +143,6 @@ public class Base64Stream extends InputStream {
return (count == 0) ? -1 : result[0] & 0xff;
}
InputStream is = InputStream.nullInputStream();
int breakPos;
boolean closed = false;
@Override
public int read(byte[] b, int off, int len) throws IOException {
if (pos == lineLength) {
@@ -166,8 +172,6 @@ public class Base64Stream extends InputStream {
return is.read(b, off, l);
}
final static int TRIPLES_INPUT = 1000;
/**
* Reads the next block of raw bytes from the source and encodes them into
* Base64. Handles stream exhaustion and final line suffix if applicable.
@@ -185,10 +189,10 @@ public class Base64Stream extends InputStream {
return;
}
if (buf.length != 3 * TRIPLES_INPUT) {
in = new ByteArrayInputStream(base64.encode(buf));
} else {
if (buf.length == 3 * TRIPLES_INPUT) {
in = new ByteArrayInputStream(base64.withoutPadding().encode(buf));
} else {
in = new ByteArrayInputStream(base64.encode(buf));
}
}
}

View File

@@ -94,6 +94,8 @@ class PiwigoExportDataContent extends AbstractExportableDataContent {
*/
public PiwigoExportDataContent(String imageFileName, String piwigoUrl, String username, String password,
String albumId) {
super();
this.imageFileName = imageFileName;
this.piwigoUrl = piwigoUrl;
this.username = username;
@@ -194,7 +196,7 @@ class PiwigoExportDataContent extends AbstractExportableDataContent {
* @return a stream containing the complete shell script
*/
private InputStream generateBashScript(InputStream originalStream) {
InputStream header = new ByteArrayInputStream(("#!/bin/bash\nset -e\n\ncurl -X POST \"" + piwigoUrl + "\" \\\n"
InputStream header = new ByteArrayInputStream(("#!/bin/bash\nset -e\n\ncurl -X POST \"" + piwigoUrl + "\" \\\n" // NOPMD
+ " -F method=\"pwg.images.add\" \\\n" + " -F username=\"" + username + "\" \\\n" + " -F password=\""
+ password + "\" \\\n" + " -F category=\"" + albumId + "\" \\\n" + " -F image=@<(base64 -d <<'EOF'\n")
.getBytes(StandardCharsets.UTF_8));
@@ -215,7 +217,7 @@ class PiwigoExportDataContent extends AbstractExportableDataContent {
*/
private InputStream generateCmdScript(InputStream originalStream) {
InputStream header = new ByteArrayInputStream(
("@echo off\nsetlocal\necho -----BEGIN BASE64----- > tmp.b64\n").getBytes(StandardCharsets.UTF_8));
"@echo off\nsetlocal\necho -----BEGIN BASE64----- > tmp.b64\n".getBytes(StandardCharsets.UTF_8));
@SuppressWarnings("resource")
InputStream body = new Base64Stream(originalStream, "echo ".getBytes(), 76, " >> tmp.b64\r\n".getBytes());