Skip to content
Open
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
3 changes: 0 additions & 3 deletions openpdf-core/src/main/java/org/openpdf/text/Jpeg2000.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,10 @@ private void processParameters() throws IOException {
originalType = ORIGINAL_JPEG2000;
inp = null;
try {
String errorID;
if (rawData == null) {
inp = url.openStream();
errorID = url.toString();
} else {
inp = new java.io.ByteArrayInputStream(rawData);
errorID = "Byte array";
}
boxLength = cio_read(4);
if (boxLength == 0x0000000c) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,6 @@ public PdfLine processLine(float leftX, float width, int alignment, int runDirec
*/
public float getWidth(int startIdx, int lastIdx) {
char c = 0;
char uniC;
PdfChunk ck = null;
float width = 0;
for (; startIdx <= lastIdx; ++startIdx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
import org.openpdf.text.utils.PdfBatch;
import org.openpdf.text.utils.PdfBatch.BatchResult;

import java.io.Closeable;

Check warning on line 58 in openpdf-core/src/main/java/org/openpdf/text/pdf/PdfBatchUtils.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused import 'java.io.Closeable'.

See more on https://sonarcloud.io/project/issues?id=LibrePDF_OpenPDF&issues=AZ0h4nXNYHjTwDlmzhA_&open=AZ0h4nXNYHjTwDlmzhA_&pullRequest=1521
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
Expand Down Expand Up @@ -234,7 +234,4 @@
public static int aes128() { return PdfWriter.ENCRYPTION_AES_128; }
public static int aes256() { return PdfWriter.ENCRYPTION_AES_256_V3; }

/** Small utility for closing Closeables, ignoring exceptions. */
private static void closeQuietly(Closeable c) { try { if (c != null) c.close(); } catch (Exception ignored) {} }

}
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,6 @@ private float remainingLinesHeight() {
return 0;
}
float result = 0;
int size = lines.size();
PdfLine line;
for (Object line1 : lines) {
line = (PdfLine) line1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,6 @@ PdfChunk truncate(float width) {
// or until the totalWidth is reached
int length = value.length();
boolean surrogate = false;
char character;
while (currentPosition < length) {
// the width of every character is added to the currentWidth
surrogate = Utilities.isSurrogatePair(value, currentPosition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ public static final byte[] convertToBytes(String text, String encoding) {
if (encoding.equals(PdfObject.TEXT_UNICODE)) {
// workaround for jdk 1.2.2 bug
char[] cc = text.toCharArray();
int len = cc.length;
byte[] b = new byte[cc.length * 2 + 2];
b[0] = -2;
b[1] = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,6 @@ private void setStrokeDiff(Stroke newStroke, Stroke oldStroke) {
cb.setLiteral("[]0 d\n");
} else {
cb.setLiteral('[');
int lim = dash.length;
for (float dash1 : dash) {
cb.setLiteral(dash1);
cb.setLiteral(' ');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ public void toPdf(PdfWriter writer, OutputStream os) throws IOException {
if (hexWriting) {
ByteBuffer buf = new ByteBuffer();
buf.append('<');
int len = b.length;
for (byte b1 : b) {
buf.appendHex(b1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ private void updateRowAdditionsInternal() {
}

// loop over all the cells
int n = newCells.size();
for (Object newCell : newCells) {
currentCell = (PdfCell) newCell;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
import org.bouncycastle.tsp.TimeStampRequestGenerator;
import org.bouncycastle.tsp.TimeStampResponse;
import org.bouncycastle.tsp.TimeStampToken;
import org.bouncycastle.tsp.TimeStampTokenInfo;

Check warning on line 70 in openpdf-core/src/main/java/org/openpdf/text/pdf/TSAClientBouncyCastle.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused import 'org.bouncycastle.tsp.TimeStampTokenInfo'.

See more on https://sonarcloud.io/project/issues?id=LibrePDF_OpenPDF&issues=AZ0h4nUZYHjTwDlmzhA-&open=AZ0h4nUZYHjTwDlmzhA-&pullRequest=1521

/**
* Time Stamp Authority Client interface implementation using Bouncy Castle org.bouncycastle.tsp package.
Expand Down Expand Up @@ -229,10 +229,8 @@
"tsa.1.failed.to.return.time.stamp.token.2", tsaURL,
response.getStatusString()));
}
TimeStampTokenInfo info = tsToken.getTimeStampInfo(); // to view
// details
byte[] encoded = tsToken.getEncoded();
long stop = System.currentTimeMillis();

// Update our token size estimate for the next call (padded to be
// safe)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public class XMLUtil {
*/
public static String escapeXML(String s, boolean onlyASCII) {
char[] cc = s.toCharArray();
int len = cc.length;
StringBuilder sb = new StringBuilder();
for (int c : cc) {
switch (c) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,38 +107,4 @@ private static String escapeXml(String s) {
return s.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;");
}

/** Extracts "x.y" from "%PDF-x.y" at file start. */
private static String extractHeaderVersion(byte[] pdfBytes) {
int len = Math.min(pdfBytes.length, 4096);
String header = new String(pdfBytes, 0, len, StandardCharsets.ISO_8859_1);
int idx = header.indexOf("%PDF-");
if (idx < 0) throw new IllegalStateException("PDF header not found");
int start = idx + 5, end = start;
while (end < header.length()) {
char c = header.charAt(end);
if (!Character.isDigit(c) && c != '.') break;
end++;
}
return header.substring(start, end);
}

/** Normalizes PdfReader#getPdfVersion(): '4' -> "1.4", "2.0" -> "2.0". May return null if not available. */
private static String getVersionFromReaderNormalized(PdfReader reader) {
try {
Method m = reader.getClass().getMethod("getPdfVersion");
Object v = m.invoke(reader);
if (v == null) return null;
if (v instanceof Character) {
char c = (Character) v;
if (Character.isDigit(c)) return "1." + c;
return String.valueOf(c);
}
if (v instanceof String) return (String) v;
} catch (NoSuchMethodException ignored) {
// Older/newer forks may differ; ignore gracefully.
} catch (Exception e) {
System.out.println("getPdfVersion() reflection error: " + e);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,6 @@ private static String parseHeaderVersion(byte[] bytes, int headerIdx) {
return new String(bytes, start, end - start, StandardCharsets.ISO_8859_1);
}

private static int countAscii(byte[] bytes, String token) {
int count = 0, idx = 0;
byte[] pat = token.getBytes(StandardCharsets.ISO_8859_1);
while ((idx = indexOf(bytes, pat, idx)) >= 0) {
count++;
idx += pat.length;
}
return count;
}

private static int indexOfAscii(byte[] bytes, String token) {
return indexOf(bytes, token.getBytes(StandardCharsets.ISO_8859_1), 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@ public void test_columnTextSeparator() throws Exception {
ct.setExtraParagraphSpace(6);
ct.setLeading(0, 1.2f);
ct.setFollowingIndent(27);
int linesWritten = 0;
int column = 0;
int status = ColumnText.START_COLUMN;
while (ColumnText.hasMoreText(status)) {
ct.setSimpleColumn(COLUMNS[column][0], COLUMNS[column][1], COLUMNS[column][2], COLUMNS[column][3]);
ct.setYLine(COLUMNS[column][3]);
status = ct.go();
linesWritten += ct.getLinesWritten();
column = Math.abs(column - 1);
if (column == 0) {
document.newPage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,43 +41,37 @@
String longTest = test.repeat(count);
assertThat(longTest.length()).as("Long enough input").isEqualTo(test.length() * count);

long total = 0;
for (int i = 0; i < 40; i++) {
long start = System.currentTimeMillis();

Check warning on line 45 in openpdf-html/src/test/java/org/openpdf/css/parser/ParserTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused "start" local variable.

See more on https://sonarcloud.io/project/issues?id=LibrePDF_OpenPDF&issues=AZ0h4nRfYHjTwDlmzhA4&open=AZ0h4nRfYHjTwDlmzhA4&pullRequest=1521
CSSParser p = new CSSParser(errorHandler);
Stylesheet stylesheet = p.parseStylesheet(null, USER_AGENT, new StringReader(longTest));
long end = System.currentTimeMillis();

Check warning on line 48 in openpdf-html/src/test/java/org/openpdf/css/parser/ParserTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused "end" local variable.

See more on https://sonarcloud.io/project/issues?id=LibrePDF_OpenPDF&issues=AZ0h4nRfYHjTwDlmzhA5&open=AZ0h4nRfYHjTwDlmzhA5&pullRequest=1521
total += (end-start);

assertThat(stylesheet.getContents()).hasSize(count);
}

total = 0;
for (int i = 0; i < 10; i++) {
long start = System.currentTimeMillis();

Check warning on line 54 in openpdf-html/src/test/java/org/openpdf/css/parser/ParserTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused "start" local variable.

See more on https://sonarcloud.io/project/issues?id=LibrePDF_OpenPDF&issues=AZ0h4nRfYHjTwDlmzhA6&open=AZ0h4nRfYHjTwDlmzhA6&pullRequest=1521
CSSParser p = new CSSParser(errorHandler);
Stylesheet stylesheet = p.parseStylesheet(null, USER_AGENT, new StringReader(longTest));
long end = System.currentTimeMillis();

Check warning on line 57 in openpdf-html/src/test/java/org/openpdf/css/parser/ParserTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused "end" local variable.

See more on https://sonarcloud.io/project/issues?id=LibrePDF_OpenPDF&issues=AZ0h4nRfYHjTwDlmzhA7&open=AZ0h4nRfYHjTwDlmzhA7&pullRequest=1521
// System.out.println("Took " + (end-start) + " ms");
total += (end-start);
assertThat(stylesheet.getContents()).hasSize(count);
}


CSSParser p = new CSSParser(errorHandler);

total = 0;
for (int i = 0; i < 10; i++) {
long start = System.currentTimeMillis();

Check warning on line 66 in openpdf-html/src/test/java/org/openpdf/css/parser/ParserTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused "start" local variable.

See more on https://sonarcloud.io/project/issues?id=LibrePDF_OpenPDF&issues=AZ0h4nRfYHjTwDlmzhA8&open=AZ0h4nRfYHjTwDlmzhA8&pullRequest=1521
for (int j = 0; j < 10000; j++) {
Stylesheet stylesheet = p.parseStylesheet(null, USER_AGENT, new StringReader(test));
assertThat(stylesheet.getURI()).isNull();
assertThat(stylesheet.getOrigin()).isEqualTo(USER_AGENT);
assertThat(stylesheet.getContents()).hasSize(1);
}
long end = System.currentTimeMillis();

Check warning on line 73 in openpdf-html/src/test/java/org/openpdf/css/parser/ParserTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused "end" local variable.

See more on https://sonarcloud.io/project/issues?id=LibrePDF_OpenPDF&issues=AZ0h4nRfYHjTwDlmzhA9&open=AZ0h4nRfYHjTwDlmzhA9&pullRequest=1521
// System.out.println("Took " + (end-start) + " ms");
total += (end-start);
}
}

Expand Down
Loading