Skip to content

Commit cd2ca4e

Browse files
Egor MartsynkovskyUbuntu
authored andcommitted
Refactor order of class methods according to iText codestyle
DEVSIX-6247
1 parent 48c61af commit cd2ca4e

File tree

1 file changed

+99
-99
lines changed

1 file changed

+99
-99
lines changed

kernel/src/main/java/com/itextpdf/kernel/pdf/PdfXrefTable.java

Lines changed: 99 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -153,88 +153,25 @@ public PdfIndirectReference get(int index) {
153153
}
154154

155155
/**
156-
* Change the state of the cross-reference table to mark that reading of the document
157-
* was completed.
158-
*/
159-
void markReadingCompleted() {
160-
readingCompleted = true;
161-
}
162-
163-
/**
164-
* Check if reading of the document was completed.
165-
*
166-
* @return true if reading was completed and false otherwise
167-
*/
168-
boolean isReadingCompleted() {
169-
return readingCompleted;
170-
}
171-
172-
/**
173-
* Set up appropriate state for the free references list.
156+
* Convenience method to write the fingerprint preceding the trailer.
157+
* The fingerprint contains information on iText products used in the generation or manipulation
158+
* of an outputted PDF file.
174159
*
175-
* @param pdfDocument is the current {@link PdfDocument document}
160+
* @param document pdfDocument to write the fingerprint to
176161
*/
177-
void initFreeReferencesList(PdfDocument pdfDocument) {
178-
freeReferencesLinkedList.clear();
179-
180-
// ensure zero object is free
181-
xref[0].setState(PdfObject.FREE);
182-
TreeSet<Integer> freeReferences = new TreeSet<>();
183-
for (int i = 1; i < size(); ++i) {
184-
PdfIndirectReference ref = xref[i];
185-
if (ref == null || ref.isFree()) {
186-
freeReferences.add(i);
187-
}
188-
}
189-
190-
PdfIndirectReference prevFreeRef = xref[0];
191-
while (!freeReferences.<Integer>isEmpty()) {
192-
int currFreeRefObjNr = -1;
193-
if (prevFreeRef.getOffset() <= Integer.MAX_VALUE) {
194-
currFreeRefObjNr = (int) prevFreeRef.getOffset();
195-
}
196-
if (!freeReferences.contains(currFreeRefObjNr) || xref[currFreeRefObjNr] == null) {
197-
break;
198-
}
199-
200-
freeReferencesLinkedList.put(currFreeRefObjNr, prevFreeRef);
201-
prevFreeRef = xref[currFreeRefObjNr];
202-
freeReferences.remove(currFreeRefObjNr);
203-
}
162+
protected static void writeKeyInfo(PdfDocument document) {
163+
PdfWriter writer = document.getWriter();
204164

205-
while (!freeReferences.<Integer>isEmpty()) {
206-
int next = freeReferences.pollFirst();
207-
if (xref[next] == null) {
208-
if (pdfDocument.properties.appendMode) {
209-
continue;
210-
}
211-
xref[next] = (PdfIndirectReference) new PdfIndirectReference(pdfDocument, next, 0).setState(PdfObject.FREE).setState(PdfObject.MODIFIED);
212-
} else if (xref[next].getGenNumber() == MAX_GENERATION && xref[next].getOffset() == 0) {
213-
continue;
214-
}
215-
if (prevFreeRef.getOffset() != (long)next) {
216-
((PdfIndirectReference) prevFreeRef.setState(PdfObject.MODIFIED)).setOffset(next);
165+
final Collection<ProductData> products = document.getFingerPrint().getProducts();
166+
if (products.isEmpty()) {
167+
writer.writeString(MessageFormatUtil
168+
.format("%iText-{0}-no-registered-products\n", ITextCoreProductData.getInstance().getVersion()));
169+
} else {
170+
for (ProductData productData : products) {
171+
writer.writeString(MessageFormatUtil
172+
.format("%iText-{0}-{1}\n", productData.getPublicProductName(), productData.getVersion()));
217173
}
218-
freeReferencesLinkedList.put(next, prevFreeRef);
219-
prevFreeRef = xref[next];
220174
}
221-
222-
if (prevFreeRef.getOffset() != 0) {
223-
((PdfIndirectReference) prevFreeRef.setState(PdfObject.MODIFIED)).setOffset(0);
224-
}
225-
freeReferencesLinkedList.put(0, prevFreeRef);
226-
}
227-
228-
/**
229-
* Method is used for object streams to avoid reuse existed references.
230-
*
231-
* @param document is the current {@link PdfDocument document}
232-
* @return created indirect reference to the object stream
233-
*/
234-
PdfIndirectReference createNewIndirectReference(PdfDocument document) {
235-
PdfIndirectReference reference = new PdfIndirectReference(document, ++count);
236-
add(reference);
237-
return (PdfIndirectReference) reference.setState(PdfObject.MODIFIED);
238175
}
239176

240177
/**
@@ -439,6 +376,91 @@ protected void writeXrefTableAndTrailer(PdfDocument document, PdfObject fileId,
439376
freeReferencesLinkedList.clear();
440377
}
441378

379+
/**
380+
* Change the state of the cross-reference table to mark that reading of the document
381+
* was completed.
382+
*/
383+
void markReadingCompleted() {
384+
readingCompleted = true;
385+
}
386+
387+
/**
388+
* Check if reading of the document was completed.
389+
*
390+
* @return true if reading was completed and false otherwise
391+
*/
392+
boolean isReadingCompleted() {
393+
return readingCompleted;
394+
}
395+
396+
/**
397+
* Set up appropriate state for the free references list.
398+
*
399+
* @param pdfDocument is the current {@link PdfDocument document}
400+
*/
401+
void initFreeReferencesList(PdfDocument pdfDocument) {
402+
freeReferencesLinkedList.clear();
403+
404+
// ensure zero object is free
405+
xref[0].setState(PdfObject.FREE);
406+
TreeSet<Integer> freeReferences = new TreeSet<>();
407+
for (int i = 1; i < size(); ++i) {
408+
PdfIndirectReference ref = xref[i];
409+
if (ref == null || ref.isFree()) {
410+
freeReferences.add(i);
411+
}
412+
}
413+
414+
PdfIndirectReference prevFreeRef = xref[0];
415+
while (!freeReferences.<Integer>isEmpty()) {
416+
int currFreeRefObjNr = -1;
417+
if (prevFreeRef.getOffset() <= Integer.MAX_VALUE) {
418+
currFreeRefObjNr = (int) prevFreeRef.getOffset();
419+
}
420+
if (!freeReferences.contains(currFreeRefObjNr) || xref[currFreeRefObjNr] == null) {
421+
break;
422+
}
423+
424+
freeReferencesLinkedList.put(currFreeRefObjNr, prevFreeRef);
425+
prevFreeRef = xref[currFreeRefObjNr];
426+
freeReferences.remove(currFreeRefObjNr);
427+
}
428+
429+
while (!freeReferences.<Integer>isEmpty()) {
430+
int next = freeReferences.pollFirst();
431+
if (xref[next] == null) {
432+
if (pdfDocument.properties.appendMode) {
433+
continue;
434+
}
435+
xref[next] = (PdfIndirectReference) new PdfIndirectReference(pdfDocument, next, 0).setState(PdfObject.FREE).setState(PdfObject.MODIFIED);
436+
} else if (xref[next].getGenNumber() == MAX_GENERATION && xref[next].getOffset() == 0) {
437+
continue;
438+
}
439+
if (prevFreeRef.getOffset() != (long)next) {
440+
((PdfIndirectReference) prevFreeRef.setState(PdfObject.MODIFIED)).setOffset(next);
441+
}
442+
freeReferencesLinkedList.put(next, prevFreeRef);
443+
prevFreeRef = xref[next];
444+
}
445+
446+
if (prevFreeRef.getOffset() != 0) {
447+
((PdfIndirectReference) prevFreeRef.setState(PdfObject.MODIFIED)).setOffset(0);
448+
}
449+
freeReferencesLinkedList.put(0, prevFreeRef);
450+
}
451+
452+
/**
453+
* Method is used for object streams to avoid reuse existed references.
454+
*
455+
* @param document is the current {@link PdfDocument document}
456+
* @return created indirect reference to the object stream
457+
*/
458+
PdfIndirectReference createNewIndirectReference(PdfDocument document) {
459+
PdfIndirectReference reference = new PdfIndirectReference(document, ++count);
460+
add(reference);
461+
return (PdfIndirectReference) reference.setState(PdfObject.MODIFIED);
462+
}
463+
442464
/**
443465
* Clear the state of the cross-reference table.
444466
*/
@@ -503,28 +525,6 @@ private int getOffsetSize(long startxref) {
503525
return size;
504526
}
505527

506-
/**
507-
* Convenience method to write the fingerprint preceding the trailer.
508-
* The fingerprint contains information on iText products used in the generation or manipulation
509-
* of an outputted PDF file.
510-
*
511-
* @param document pdfDocument to write the fingerprint to
512-
*/
513-
protected static void writeKeyInfo(PdfDocument document) {
514-
PdfWriter writer = document.getWriter();
515-
516-
final Collection<ProductData> products = document.getFingerPrint().getProducts();
517-
if (products.isEmpty()) {
518-
writer.writeString(MessageFormatUtil
519-
.format("%iText-{0}-no-registered-products\n", ITextCoreProductData.getInstance().getVersion()));
520-
} else {
521-
for (ProductData productData : products) {
522-
writer.writeString(MessageFormatUtil
523-
.format("%iText-{0}-{1}\n", productData.getPublicProductName(), productData.getVersion()));
524-
}
525-
}
526-
}
527-
528528
private void appendNewRefToFreeList(PdfIndirectReference reference) {
529529
reference.setOffset(0);
530530
if (freeReferencesLinkedList.<Integer, PdfIndirectReference>isEmpty()) {

0 commit comments

Comments
 (0)