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; protected DataContent input;
/**
* Default constructor.
*/
public AbstractExportableDataContent() {
// empty
}
/** /**
* Sets the input {@link DataContent} for export. * Sets the input {@link DataContent} for export.
* *

View File

@@ -94,12 +94,20 @@ import java.util.Base64.Encoder;
*/ */
public class Base64Stream extends InputStream { public class Base64Stream extends InputStream {
InputStream source; private final InputStream source;
InputStream in, prefix, suffix; private InputStream in;
Encoder base64; private InputStream prefix;
int pos = 0; private InputStream suffix;
final int lineLength; private final Encoder base64;
int lineBreak; 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}. * Constructs a new {@code Base64Stream}.
@@ -113,9 +121,11 @@ public class Base64Stream extends InputStream {
* newline); can be {@code null} * newline); can be {@code null}
*/ */
public Base64Stream(InputStream source, byte[] linePrefix, int lineLength, byte[] lineSuffix) { public Base64Stream(InputStream source, byte[] linePrefix, int lineLength, byte[] lineSuffix) {
super();
this.source = source; this.source = source;
this.lineLength = lineLength; this.lineLength = lineLength;
in = InputStream.nullInputStream(); in = nullInputStream();
base64 = Base64.getEncoder(); base64 = Base64.getEncoder();
if (linePrefix != null) { if (linePrefix != null) {
prefix = new ByteArrayInputStream(linePrefix); prefix = new ByteArrayInputStream(linePrefix);
@@ -133,10 +143,6 @@ public class Base64Stream extends InputStream {
return (count == 0) ? -1 : result[0] & 0xff; return (count == 0) ? -1 : result[0] & 0xff;
} }
InputStream is = InputStream.nullInputStream();
int breakPos;
boolean closed = false;
@Override @Override
public int read(byte[] b, int off, int len) throws IOException { public int read(byte[] b, int off, int len) throws IOException {
if (pos == lineLength) { if (pos == lineLength) {
@@ -166,8 +172,6 @@ public class Base64Stream extends InputStream {
return is.read(b, off, l); 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 * Reads the next block of raw bytes from the source and encodes them into
* Base64. Handles stream exhaustion and final line suffix if applicable. * Base64. Handles stream exhaustion and final line suffix if applicable.
@@ -185,10 +189,10 @@ public class Base64Stream extends InputStream {
return; return;
} }
if (buf.length != 3 * TRIPLES_INPUT) { if (buf.length == 3 * TRIPLES_INPUT) {
in = new ByteArrayInputStream(base64.encode(buf));
} else {
in = new ByteArrayInputStream(base64.withoutPadding().encode(buf)); 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, public PiwigoExportDataContent(String imageFileName, String piwigoUrl, String username, String password,
String albumId) { String albumId) {
super();
this.imageFileName = imageFileName; this.imageFileName = imageFileName;
this.piwigoUrl = piwigoUrl; this.piwigoUrl = piwigoUrl;
this.username = username; this.username = username;
@@ -194,7 +196,7 @@ class PiwigoExportDataContent extends AbstractExportableDataContent {
* @return a stream containing the complete shell script * @return a stream containing the complete shell script
*/ */
private InputStream generateBashScript(InputStream originalStream) { 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=\"" + " -F method=\"pwg.images.add\" \\\n" + " -F username=\"" + username + "\" \\\n" + " -F password=\""
+ password + "\" \\\n" + " -F category=\"" + albumId + "\" \\\n" + " -F image=@<(base64 -d <<'EOF'\n") + password + "\" \\\n" + " -F category=\"" + albumId + "\" \\\n" + " -F image=@<(base64 -d <<'EOF'\n")
.getBytes(StandardCharsets.UTF_8)); .getBytes(StandardCharsets.UTF_8));
@@ -215,7 +217,7 @@ class PiwigoExportDataContent extends AbstractExportableDataContent {
*/ */
private InputStream generateCmdScript(InputStream originalStream) { private InputStream generateCmdScript(InputStream originalStream) {
InputStream header = new ByteArrayInputStream( 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") @SuppressWarnings("resource")
InputStream body = new Base64Stream(originalStream, "echo ".getBytes(), 76, " >> tmp.b64\r\n".getBytes()); InputStream body = new Base64Stream(originalStream, "echo ".getBytes(), 76, " >> tmp.b64\r\n".getBytes());