You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2019/12/07 17:53:42 UTC
svn commit: r1870999 - in /pdfbox/trunk:
debugger/src/main/java/org/apache/pdfbox/debugger/fontencodingpane/
pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/
pdfbox/src/main/java/org/apache/pdfbox/util/filetypedetector/
pdfbox/src/test/java/org/apache...
Author: tilman
Date: Sat Dec 7 17:53:42 2019
New Revision: 1870999
URL: http://svn.apache.org/viewvc?rev=1870999&view=rev
Log:
PDFBOX-4071: use standard charset
Modified:
pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/fontencodingpane/Type3Font.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/ContentStreamWriter.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/filetypedetector/FileTypeDetector.java
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java
Modified: pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/fontencodingpane/Type3Font.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/fontencodingpane/Type3Font.java?rev=1870999&r1=1870998&r2=1870999&view=diff
==============================================================================
--- pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/fontencodingpane/Type3Font.java (original)
+++ pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/fontencodingpane/Type3Font.java Sat Dec 7 17:53:42 2019
@@ -18,6 +18,7 @@ package org.apache.pdfbox.debugger.fonte
import java.awt.image.BufferedImage;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -34,7 +35,6 @@ import org.apache.pdfbox.pdmodel.font.PD
import org.apache.pdfbox.pdmodel.font.PDType3CharProc;
import org.apache.pdfbox.pdmodel.font.PDType3Font;
import org.apache.pdfbox.rendering.PDFRenderer;
-import org.apache.pdfbox.util.Charsets;
import org.apache.pdfbox.util.Matrix;
/**
@@ -182,7 +182,7 @@ class Type3Font extends FontPane
cs.beginText();
cs.setFont(font, scale / Math.min(Math.abs(scalingFactorX), Math.abs(scalingFactorY)));
// can't use showText() because there's no guarantee we have the unicode
- cs.appendRawCommands(String.format("<%02X> Tj\n", index).getBytes(Charsets.ISO_8859_1));
+ cs.appendRawCommands(String.format("<%02X> Tj\n", index).getBytes(StandardCharsets.ISO_8859_1));
cs.endText();
}
doc.addPage(page);
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/ContentStreamWriter.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/ContentStreamWriter.java?rev=1870999&r1=1870998&r2=1870999&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/ContentStreamWriter.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/ContentStreamWriter.java Sat Dec 7 17:53:42 2019
@@ -18,6 +18,7 @@ package org.apache.pdfbox.pdfwriter;
import java.io.IOException;
import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import org.apache.pdfbox.contentstream.operator.Operator;
@@ -30,7 +31,6 @@ import org.apache.pdfbox.cos.COSFloat;
import org.apache.pdfbox.cos.COSInteger;
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.cos.COSString;
-import org.apache.pdfbox.util.Charsets;
/**
* A class that will take a list of tokens and write out a stream with them.
@@ -94,7 +94,7 @@ public class ContentStreamWriter
{
writeObject(token);
}
- output.write("\n".getBytes(Charsets.US_ASCII));
+ output.write("\n".getBytes(StandardCharsets.US_ASCII));
}
/**
@@ -172,7 +172,7 @@ public class ContentStreamWriter
Operator op = (Operator)o;
if( op.getName().equals( OperatorName.BEGIN_INLINE_IMAGE ) )
{
- output.write( OperatorName.BEGIN_INLINE_IMAGE.getBytes(Charsets.ISO_8859_1) );
+ output.write( OperatorName.BEGIN_INLINE_IMAGE.getBytes(StandardCharsets.ISO_8859_1) );
COSDictionary dic = op.getImageParameters();
for( COSName key : dic.keySet() )
{
@@ -182,16 +182,16 @@ public class ContentStreamWriter
writeObject( value );
output.write( EOL );
}
- output.write( OperatorName.BEGIN_INLINE_IMAGE_DATA.getBytes(Charsets.ISO_8859_1) );
+ output.write( OperatorName.BEGIN_INLINE_IMAGE_DATA.getBytes(StandardCharsets.ISO_8859_1) );
output.write( EOL );
output.write( op.getImageData() );
output.write( EOL );
- output.write( OperatorName.END_INLINE_IMAGE.getBytes(Charsets.ISO_8859_1) );
+ output.write( OperatorName.END_INLINE_IMAGE.getBytes(StandardCharsets.ISO_8859_1) );
output.write( EOL );
}
else
{
- output.write( op.getName().getBytes(Charsets.ISO_8859_1) );
+ output.write( op.getName().getBytes(StandardCharsets.ISO_8859_1) );
output.write( EOL );
}
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/filetypedetector/FileTypeDetector.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/filetypedetector/FileTypeDetector.java?rev=1870999&r1=1870998&r2=1870999&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/filetypedetector/FileTypeDetector.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/filetypedetector/FileTypeDetector.java Sat Dec 7 17:53:42 2019
@@ -18,8 +18,7 @@ package org.apache.pdfbox.util.filetyped
import java.io.BufferedInputStream;
import java.io.IOException;
-
-import org.apache.pdfbox.util.Charsets;
+import java.nio.charset.StandardCharsets;
/**
* @author Drew Noakes
@@ -44,31 +43,31 @@ public final class FileTypeDetector
// https://en.wikipedia.org/wiki/List_of_file_signatures
root.addPath(FileType.JPEG, new byte[]{(byte)0xff, (byte)0xd8});
- root.addPath(FileType.TIFF, "II".getBytes(Charsets.ISO_8859_1), new byte[]{0x2a, 0x00});
- root.addPath(FileType.TIFF, "MM".getBytes(Charsets.ISO_8859_1), new byte[]{0x00, 0x2a});
- root.addPath(FileType.PSD, "8BPS".getBytes(Charsets.ISO_8859_1));
+ root.addPath(FileType.TIFF, "II".getBytes(StandardCharsets.ISO_8859_1), new byte[]{0x2a, 0x00});
+ root.addPath(FileType.TIFF, "MM".getBytes(StandardCharsets.ISO_8859_1), new byte[]{0x00, 0x2a});
+ root.addPath(FileType.PSD, "8BPS".getBytes(StandardCharsets.ISO_8859_1));
root.addPath(FileType.PNG, new byte[]{(byte)0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52});
// TODO technically there are other very rare magic numbers for OS/2 BMP files...
- root.addPath(FileType.BMP, "BM".getBytes(Charsets.ISO_8859_1));
- root.addPath(FileType.GIF, "GIF87a".getBytes(Charsets.ISO_8859_1));
- root.addPath(FileType.GIF, "GIF89a".getBytes(Charsets.ISO_8859_1));
+ root.addPath(FileType.BMP, "BM".getBytes(StandardCharsets.ISO_8859_1));
+ root.addPath(FileType.GIF, "GIF87a".getBytes(StandardCharsets.ISO_8859_1));
+ root.addPath(FileType.GIF, "GIF89a".getBytes(StandardCharsets.ISO_8859_1));
root.addPath(FileType.ICO, new byte[]{0x00, 0x00, 0x01, 0x00});
// multiple PCX versions, explicitly listed
root.addPath(FileType.PCX, new byte[]{0x0A, 0x00, 0x01});
root.addPath(FileType.PCX, new byte[]{0x0A, 0x02, 0x01});
root.addPath(FileType.PCX, new byte[]{0x0A, 0x03, 0x01});
root.addPath(FileType.PCX, new byte[]{0x0A, 0x05, 0x01});
- root.addPath(FileType.RIFF, "RIFF".getBytes(Charsets.ISO_8859_1));
+ root.addPath(FileType.RIFF, "RIFF".getBytes(StandardCharsets.ISO_8859_1));
// https://github.com/drewnoakes/metadata-extractor/issues/217
- // root.addPath(FileType.ARW, "II".getBytes(Charsets.ISO_8859_1), new byte[]{0x2a, 0x00, 0x08, 0x00})
- root.addPath(FileType.CRW, "II".getBytes(Charsets.ISO_8859_1), new byte[]{0x1a, 0x00, 0x00, 0x00}, "HEAPCCDR".getBytes(Charsets.ISO_8859_1));
- root.addPath(FileType.CR2, "II".getBytes(Charsets.ISO_8859_1), new byte[]{0x2a, 0x00, 0x10, 0x00, 0x00, 0x00, 0x43, 0x52});
- root.addPath(FileType.NEF, "MM".getBytes(Charsets.ISO_8859_1), new byte[]{0x00, 0x2a, 0x00, 0x00, 0x00, (byte)0x80, 0x00});
- root.addPath(FileType.ORF, "IIRO".getBytes(Charsets.ISO_8859_1), new byte[]{(byte)0x08, 0x00});
- root.addPath(FileType.ORF, "IIRS".getBytes(Charsets.ISO_8859_1), new byte[]{(byte)0x08, 0x00});
- root.addPath(FileType.RAF, "FUJIFILMCCD-RAW".getBytes(Charsets.ISO_8859_1));
- root.addPath(FileType.RW2, "II".getBytes(Charsets.ISO_8859_1), new byte[]{0x55, 0x00});
+ // root.addPath(FileType.ARW, "II".getBytes(StandardCharsets.ISO_8859_1), new byte[]{0x2a, 0x00, 0x08, 0x00})
+ root.addPath(FileType.CRW, "II".getBytes(StandardCharsets.ISO_8859_1), new byte[]{0x1a, 0x00, 0x00, 0x00}, "HEAPCCDR".getBytes(StandardCharsets.ISO_8859_1));
+ root.addPath(FileType.CR2, "II".getBytes(StandardCharsets.ISO_8859_1), new byte[]{0x2a, 0x00, 0x10, 0x00, 0x00, 0x00, 0x43, 0x52});
+ root.addPath(FileType.NEF, "MM".getBytes(StandardCharsets.ISO_8859_1), new byte[]{0x00, 0x2a, 0x00, 0x00, 0x00, (byte)0x80, 0x00});
+ root.addPath(FileType.ORF, "IIRO".getBytes(StandardCharsets.ISO_8859_1), new byte[]{(byte)0x08, 0x00});
+ root.addPath(FileType.ORF, "IIRS".getBytes(StandardCharsets.ISO_8859_1), new byte[]{(byte)0x08, 0x00});
+ root.addPath(FileType.RAF, "FUJIFILMCCD-RAW".getBytes(StandardCharsets.ISO_8859_1));
+ root.addPath(FileType.RW2, "II".getBytes(StandardCharsets.ISO_8859_1), new byte[]{0x55, 0x00});
}
private FileTypeDetector()
Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java?rev=1870999&r1=1870998&r2=1870999&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java Sat Dec 7 17:53:42 2019
@@ -23,6 +23,7 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
@@ -47,7 +48,6 @@ import org.apache.pdfbox.pdmodel.encrypt
import org.apache.pdfbox.pdmodel.encryption.StandardSecurityHandler;
import org.apache.pdfbox.pdmodel.graphics.image.ValidateXImage;
import org.apache.pdfbox.rendering.PDFRenderer;
-import org.apache.pdfbox.util.Charsets;
import org.junit.Assert;
/**
@@ -398,11 +398,11 @@ public class TestSymmetricKeyEncryption
StandardSecurityHandler standardSecurityHandler = new StandardSecurityHandler();
int keyLengthInBytes = encryption.getVersion() == 1 ? 5 : encryption.getLength() / 8;
byte[] computedUserPassword = standardSecurityHandler.getUserPassword(
- ownerpassword.getBytes(Charsets.ISO_8859_1),
+ ownerpassword.getBytes(StandardCharsets.ISO_8859_1),
encryption.getOwnerKey(),
revision,
keyLengthInBytes);
- Assert.assertEquals(userpassword.substring(0, 32), new String(computedUserPassword, Charsets.ISO_8859_1));
+ Assert.assertEquals(userpassword.substring(0, 32), new String(computedUserPassword, StandardCharsets.ISO_8859_1));
}
encryptedDoc.close();