Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-79 nio object parser #251

Merged
merged 59 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
e71c161
GH-79 a sort of, kind of, working prototype
Mar 8, 2022
f363451
GH-79 a sort of, kind of, working a slightly better
Mar 10, 2022
cbfe61c
GH-79 small wins, still lots of work to do.
Jun 3, 2022
e663f91
Merge branch 'master' into GH-79.nio.object.parser
Jun 29, 2022
478f230
GH-79 fix unrelated annotation parsing error.
Nov 10, 2022
f9639a2
GH-79 fix parser offset issue.
Nov 10, 2022
37e83dd
GH-79 update logger
Nov 10, 2022
4120230
GH-79 fix decimal parsing
Nov 10, 2022
e019773
GH-79 some debug helpers
Nov 10, 2022
c7d0a1d
GH-79 fix encryption reference passthrough when parsing arrays
Nov 11, 2022
300513b
GH-79 fix nasty CrossReferenceTable error where subgroups were not pa…
Nov 12, 2022
4a8aeaa
Merge branch 'master' into GH-79.nio.object.parser
Nov 14, 2022
f239c64
GH-79 more encryption reference issues.
Nov 14, 2022
bf7002e
GH-79 fix DictionaryEntries type changes in the lexer.
Nov 17, 2022
0dd8f54
GH-79 touch up white space handling for streams
Nov 19, 2022
406fd56
GH-79 fix incorrect starting object number when parsing xref table
Nov 19, 2022
9a365c5
GH-79 little code clean up.
Nov 23, 2022
efe4d77
GH-79 address parser issue where know types were not returned as obje…
Dec 2, 2022
117a802
Merge branch 'master' into GH-79.nio.object.parser
Jan 13, 2023
7c4de19
Merge branch 'master' into GH-79.nio.object.parser
Jan 13, 2023
cc9e916
GH-79 fix issue trying to load a font data stream as a font object.
Jan 17, 2023
f6cdbb3
GH-79 fix issue where zeroed stream wasn't taking into account the en…
Jan 17, 2023
85312d0
GH-79 make sure we don't clear a valid font bbox.
Jan 17, 2023
814e55c
GH-79 further refinement of the approach.
Jan 22, 2023
e3dcf68
GH-79 cleaned up stream and table cross-reference common code as well…
Jan 23, 2023
70f8c93
GH-79 further clean up and brought back incremental updates for table…
Jan 24, 2023
d2bcdc7
GH-79 attempted cleanup/removal of throwable from code base.
Jan 25, 2023
a2b39a5
GH-80 fix some missing 2 byte hex values from not being rendering cor…
Jan 25, 2023
3c23ad7
GH-79 remove redundant new BufferedOutputStream wrapper.
Jan 25, 2023
34c8282
GH-79 clean up extra new line creation.
Jan 25, 2023
fad1274
GH-79 todo cleanup
Jan 25, 2023
fb53c96
GH-79 refactor a recursive call that was getting away and not really …
Jan 27, 2023
e42ff2b
GH-79 standardize buffer sizes for and minimize parser creation
Jan 29, 2023
8257457
GH-79 fix missing generation when adding a used entry.
Jan 30, 2023
46ed19e
GH-79 fix layer visibility state issue by pulling from catalog when p…
Feb 1, 2023
d572719
GH-79 more exception handling and logging touchups.
Feb 2, 2023
9829529
GH-79 more logging touch ups.
Feb 3, 2023
6b64e7d
GH-79 revert PdfSecurityException change
Feb 3, 2023
4abab2d
GH-79 touch up digital signatures to use the new nio file access.
Feb 8, 2023
00bdb64
GH-79 fix nasty offset issue when reindexing and looking for xref pos…
Feb 14, 2023
1a283d3
GH-79 move annotation to soft references so we less likely to lose re…
Feb 15, 2023
a61d70c
Merge branch 'master' into GH-79.nio.object.parser
Feb 15, 2023
233a2e2
GH-79 revert back to 4 threads.
Feb 16, 2023
a643c74
GH-79 attempt to fix attachments, not there yet
Feb 16, 2023
2ff1c0b
GH-79 migrated to slice over buffer get operations.
Feb 17, 2023
d317f31
GH-79 reworked Parser.getPObject to handle attachments that can span …
Feb 18, 2023
6f6c0da
GH-79 touch up artifacts on icon.
Feb 18, 2023
8850669
GH-79 touch up artifacts on icon.
Feb 18, 2023
81aced7
GH-79 fix issue when loading a catalogue followed by a regular docume…
Feb 18, 2023
e136ee9
GH-79 code clean up
Feb 22, 2023
727afdf
GH-79 code clean up
Feb 22, 2023
7178314
GH-79 more code clean up
Feb 23, 2023
1952e59
GH-79 code clean up
Feb 24, 2023
6186daa
GH-79 code clean up
Feb 24, 2023
10f8261
GH-79 code clean up
Feb 24, 2023
e19723a
GH-79 code clean up
Feb 27, 2023
09fe6a2
GH-79 misc. log combing fixes.
Mar 9, 2023
43625d8
GH-79 address concurrent access/modification during page init when a …
Mar 9, 2023
6450ca1
Merge branch 'master' into GH-79.nio.object.parser
Mar 9, 2023
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
Prev Previous commit
Next Next commit
GH-79 touch up digital signatures to use the new nio file access.
  • Loading branch information
Patrick Corless committed Feb 8, 2023
commit 4abab2de9e6026dc694b4937c27dbac04743acd5
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ public int available() {
try {
return (int) (m_RandomAccessFile.getFilePointer());
} catch (IOException e) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.WARNING, "Error calling available", e);
}
logger.log(Level.WARNING, "Error calling available", e);
}
return 0;
}
Expand Down
80 changes: 35 additions & 45 deletions core/core-awt/src/main/java/org/icepdf/core/pobjects/Catalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ public class Catalog extends Dictionary {

// Announce ICEpdf Core
static {
if (logger.isLoggable(Level.INFO)) {
logger.info("ICEpdf Core " + Document.getLibraryVersion());
}
logger.log(Level.INFO, () -> "ICEpdf Core " + Document.getLibraryVersion());
}

public Catalog(Library library, DictionaryEntries dictionaryEntries) {
Expand Down Expand Up @@ -160,15 +158,13 @@ public PageTree getPageTree() {
* {@link OutlineItem}
*/
public Outlines getOutlines() {
if (!outlinesInited) {
synchronized (this) {
if (!outlinesInited) {
Object o = library.getObject(entries, OUTLINES_KEY);
if (o != null) {
outlines = new Outlines(library, (DictionaryEntries) o);
}
outlinesInited = true;
synchronized (this) {
if (!outlinesInited) {
Object o = library.getObject(entries, OUTLINES_KEY);
if (o != null) {
outlines = new Outlines(library, (DictionaryEntries) o);
}
outlinesInited = true;
}
}
return outlines;
Expand Down Expand Up @@ -294,15 +290,13 @@ public NameTree getEmbeddedFilesNameTree() {
*/
@SuppressWarnings("unchecked")
public NamedDestinations getDestinations() {
if (!destsInited) {
synchronized (this) {
if (!destsInited) {
Object o = library.getObject(entries, DESTS_KEY);
if (o instanceof DictionaryEntries) {
dests = new NamedDestinations(library, (DictionaryEntries) o);
}
destsInited = true;
synchronized (this) {
if (!destsInited) {
Object o = library.getObject(entries, DESTS_KEY);
if (o instanceof DictionaryEntries) {
dests = new NamedDestinations(library, (DictionaryEntries) o);
}
destsInited = true;
}
}
return dests;
Expand All @@ -316,22 +310,20 @@ public NamedDestinations getDestinations() {
* @return the constructed ViewerPreferences object
*/
public ViewerPreferences getViewerPreferences() {
if (!viewerPrefInited) {
synchronized (this) {
if (!viewerPrefInited) {
Object o = library.getObject(entries, VIEWERPREFERENCES_KEY);
if (o != null) {
if (o instanceof DictionaryEntries) {
viewerPref = new ViewerPreferences(library, (DictionaryEntries) o);
viewerPref.init();
} // strange corner case where there is a incorrect reference.
else if (o instanceof Catalog) {
viewerPref = new ViewerPreferences(library, ((Catalog) o).getEntries());
viewerPref.init();
}
synchronized (this) {
if (!viewerPrefInited) {
Object o = library.getObject(entries, VIEWERPREFERENCES_KEY);
if (o != null) {
if (o instanceof DictionaryEntries) {
viewerPref = new ViewerPreferences(library, (DictionaryEntries) o);
viewerPref.init();
} // strange corner case where there is a incorrect reference.
else if (o instanceof Catalog) {
viewerPref = new ViewerPreferences(library, ((Catalog) o).getEntries());
viewerPref.init();
}
viewerPrefInited = true;
}
viewerPrefInited = true;
}
}
return viewerPref;
Expand All @@ -343,19 +335,17 @@ else if (o instanceof Catalog) {
* @return OptionalContent dictionary, null if none exists.
*/
public OptionalContent getOptionalContent() {
if (!optionalContentInited) {
synchronized (this) {
if (!optionalContentInited) {
Object o = library.getObject(entries, OCPROPERTIES_KEY);
if (o instanceof DictionaryEntries) {
optionalContent = new OptionalContent(library, (DictionaryEntries) o);
optionalContent.init();
} else {
optionalContent = new OptionalContent(library, new DictionaryEntries());
optionalContent.init();
}
optionalContentInited = true;
synchronized (this) {
if (!optionalContentInited) {
Object o = library.getObject(entries, OCPROPERTIES_KEY);
if (o instanceof DictionaryEntries) {
optionalContent = new OptionalContent(library, (DictionaryEntries) o);
optionalContent.init();
} else {
optionalContent = new OptionalContent(library, new DictionaryEntries());
optionalContent.init();
}
optionalContentInited = true;
}
}
return optionalContent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,7 @@ else if (object instanceof Name || object instanceof StringObject) {
else if (ob instanceof HashMap) {
parse((List) (((HashMap) ob).get(D_KEY)));
} else {
if (logger.isLoggable(Level.FINE)) {
logger.warning("Destination type missed=" + ob);
}
logger.log(Level.FINE, () -> "Destination type missed=" + ob);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void setWatermarkCallback(WatermarkCallback watermarkCallback) {
*/
private void setDocumentOrigin(String o) {
origin = o;
if (logger.isLoggable(Level.CONFIG)) {
if (logger.isLoggable(Level.FINE)) {
logger.config(
"MEMFREE: " + Runtime.getRuntime().freeMemory() + " of " +
Runtime.getRuntime().totalMemory());
Expand Down Expand Up @@ -542,8 +542,8 @@ public void dispose() {
if (fileToDelete != null) {
File file = new File(fileToDelete);
boolean success = file.delete();
if (!success && logger.isLoggable(Level.WARNING)) {
logger.warning("Error deleting URL cached to file " + fileToDelete);
if (!success) {
logger.log(Level.WARNING, () -> "Error deleting URL cached to file " + fileToDelete);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,7 @@ public synchronized void init() throws InterruptedException {
byte[] in = getDecodedStreamBytes();
if (in != null) {
try {
if (logger.isLoggable(Level.FINER)) {
logger.finer("Parsing form " + getPObjectReference());
}
logger.log(Level.FINER, () -> "Parsing form " + getPObjectReference());
shapes = cp.parse(new byte[][]{in}, new Reference[]{this.getPObjectReference()}, null).getShapes();
inited = true;
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,8 @@ public int getUnsignedInt(int start, int offset) {
unsignedInt = Integer.parseInt(
stringData.substring(start, start + offset), 16);
} catch (NumberFormatException e) {
if (logger.isLoggable(Level.FINER)) {
logger.finer("Number Format Exception " + unsignedInt + " " + stringData.substring(start, start + offset));
}
int finalUnsignedInt = unsignedInt;
logger.log(Level.FINER, () -> "Number Format Exception " + finalUnsignedInt + " " + stringData.substring(start, start + offset));
}
return unsignedInt;
}
Expand All @@ -153,9 +152,8 @@ public int getUnsignedInt(String data) {
try {
unsignedInt = Integer.parseInt(data, 16);
} catch (NumberFormatException e) {
if (logger.isLoggable(Level.FINER)) {
logger.finer("Number Format Exception " + unsignedInt);
}
int finalUnsignedInt = unsignedInt;
logger.log(Level.FINER, () -> "Number Format Exception " + finalUnsignedInt);
}
return unsignedInt;
}
Expand Down Expand Up @@ -239,7 +237,7 @@ public StringBuilder getLiteralStringBuffer(final int fontFormat, FontFile font)
// 0 cid is valid, so we have ot be careful we don't exclude the
// cid 00 = 0 or 0000 = 0, not 0000 = 00.
// removed font check as it was causing problems with a lot of Latin based hex strings
// may need to revisit in the future when getting back to multibyte encodings.
// may need to revisit in the future when getting back to multibyte encodings.
if (!(offset < length && charValue == 0)) {
tmp.append((char) charValue);
lastIndex = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,8 @@ public org.icepdf.core.pobjects.fonts.Font getFont(Name s) {
org.icepdf.core.pobjects.fonts.Font font = null;
if (fonts != null) {
Object ob = fonts.get(s);
// check to make sure the library contains a font
if (ob instanceof org.icepdf.core.pobjects.fonts.Font) {
font = (org.icepdf.core.pobjects.fonts.Font) ob;
}
// corner case where font is just a inline dictionary.
else if (ob instanceof DictionaryEntries) {
font = FontFactory.getInstance().getFont(library, (DictionaryEntries) ob);
}
// the default value is most likely Reference
else if (ob instanceof Reference) {
if (ob instanceof Reference) {
Reference ref = (Reference) ob;
ob = library.getObject((Reference) ob);
if (ob instanceof org.icepdf.core.pobjects.fonts.Font) {
Expand All @@ -140,6 +132,14 @@ else if (ob instanceof Reference) {
font.setPObjectReference(ref);
}
}
// check to make sure the library contains a font
else if (ob instanceof org.icepdf.core.pobjects.fonts.Font) {
font = (org.icepdf.core.pobjects.fonts.Font) ob;
}
// corner case where font is just a inline dictionary.
else if (ob instanceof DictionaryEntries) {
font = FontFactory.getInstance().getFont(library, (DictionaryEntries) ob);
}
// if still null do a deeper search checking the base font name of
// each font for a match to the needed font name. We have a few
// malformed documents that don't refer to a font by the base name
Expand Down
Loading