Skip to content

Commit 040086f

Browse files
author
Egor Martsynkovsky
committed
Move JsonUtil class to commons module
Add ability to deserealize Json from stream Add zip functionality PDWEB-61
1 parent ad769e9 commit 040086f

28 files changed

+1752
-4
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*.xht text eol=lf
2121
*.xhtml text eol=lf
2222
*.xml text eol=lf
23+
*.json text eol=lf
2324
port-hash text eol=lf
2425

2526
# Declare files that will always have CRLF line endings on checkout.

commons/pom.xml

+11
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,18 @@
1010
<name>iText 7 - commons</name>
1111
<url>https://itextpdf.com/</url>
1212

13+
<properties>
14+
<jackson.core.version>2.13.2</jackson.core.version>
15+
</properties>
16+
1317
<dependencies>
18+
<dependency>
19+
<groupId>com.fasterxml.jackson.core</groupId>
20+
<artifactId>jackson-databind</artifactId>
21+
<version>${jackson.core.version}</version>
22+
<optional>true</optional>
23+
</dependency>
24+
1425
<dependency>
1526
<groupId>com.itextpdf</groupId>
1627
<artifactId>pdftest</artifactId>

commons/src/main/java/com/itextpdf/commons/exceptions/CommonsExceptionMessageConstant.java

+16-3
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,28 @@ public final class CommonsExceptionMessageConstant {
3636
*/
3737
public static final String ELEMENT_ALREADY_HAS_IDENTIFIER = "Element already has sequence id: {0}, new id {1} " +
3838
"will be ignored";
39+
40+
public static final String FILE_SHOULD_EXIST = "File should exist.";
41+
public static final String FILE_NAME_ALREADY_EXIST = "File name: {0}, already exists.";
42+
public static final String FILE_NAME_CAN_NOT_BE_NULL = "File name can not be null.";
43+
public static final String FILE_NAME_SHOULD_BE_UNIQUE = "File name should be unique.";
3944
public static final String INVALID_USAGE_CONFIGURATION_FORBIDDEN = "Invalid usage of placeholder \"{0}\": any "
4045
+ "configuration is forbidden";
41-
public static final String INVALID_USAGE_FORMAT_REQUIRED = "Invalid usage of placeholder \"{0}\": format is required";
42-
public static final String NO_EVENTS_WERE_REGISTERED_FOR_THE_DOCUMENT = "No events were registered for the document!";
46+
public static final String INVALID_USAGE_FORMAT_REQUIRED = "Invalid usage of placeholder \"{0}\": format is "
47+
+ "required";
48+
public static final String JSON_OBJECT_CAN_NOT_BE_NULL = "Passed json object can not be null";
49+
public static final String NO_EVENTS_WERE_REGISTERED_FOR_THE_DOCUMENT = "No events were registered for the "
50+
+ "document!";
4351
public static final String PATTERN_CONTAINS_OPEN_QUOTATION = "Pattern contains open quotation!";
4452
public static final String PATTERN_CONTAINS_UNEXPECTED_CHARACTER = "Pattern contains unexpected character {0}";
4553
public static final String PATTERN_CONTAINS_UNEXPECTED_COMPONENT = "Pattern contains unexpected component {0}";
4654
public static final String PRODUCT_NAME_CAN_NOT_BE_NULL = "Product name can not be null.";
55+
public static final String STREAM_CAN_NOT_BE_NULL = "Passed stream can not be null";
4756
public static final String UNKNOWN_ITEXT_EXCEPTION = "Unknown ITextException.";
4857

49-
private CommonsExceptionMessageConstant(){}
58+
public static final String ZIP_ENTRY_NOT_FOUND = "Zip entry not found for name: {0}";
59+
60+
private CommonsExceptionMessageConstant() {
61+
// Empty constructor.
62+
}
5063
}

commons/src/main/java/com/itextpdf/commons/logs/CommonsLogMessageConstant.java

+35-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,40 @@ public final class CommonsLogMessageConstant {
5757
public static final String INVALID_STATISTICS_NAME =
5858
"Statistics name {0} is invalid. Cannot find corresponding statistics aggregator.";
5959

60+
/**
61+
* Message notifies that files archiving operation failed.
62+
*
63+
* <ul>
64+
* <li>0th is a message of thrown exception;
65+
* </ul>
66+
*/
67+
public static final String LOCAL_FILE_COMPRESSION_FAILED = "Cannot archive files into zip. "
68+
+ "Exception message: {0}.";
69+
70+
/**
71+
* Message notifies that some exception has been thrown during json deserialization from object.
72+
* List of params:
73+
*
74+
* <ul>
75+
* <li>0th is a class name of thrown exception;
76+
* <li>1st is a message of thrown exception;
77+
* </ul>
78+
*/
79+
public static final String UNABLE_TO_DESERIALIZE_JSON =
80+
"Unable to deserialize json. Exception {0} was thrown with the message: {1}.";
81+
82+
/**
83+
* Message notifies that some exception has been thrown during json serialization to object.
84+
* List of params:
85+
*
86+
* <ul>
87+
* <li>0th is a class name of thrown exception;
88+
* <li>1st is a message of thrown exception;
89+
* </ul>
90+
*/
91+
public static final String UNABLE_TO_SERIALIZE_OBJECT =
92+
"Unable to serialize object. Exception {0} was thrown with the message: {1}.";
93+
6094
/**
6195
* Message notifies that unknown placeholder was ignored during parsing of the producer line
6296
* format. List of params:
@@ -81,6 +115,6 @@ public final class CommonsLogMessageConstant {
81115
+ "Probably appropriate process fail";
82116

83117
private CommonsLogMessageConstant() {
84-
//Private constructor will prevent the instantiation of this class directly
118+
// Private constructor will prevent the instantiation of this class directly.
85119
}
86120
}

commons/src/main/java/com/itextpdf/commons/utils/FileUtil.java

+8
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ public static java.io.OutputStream wrapWithBufferedOutputStream(OutputStream out
209209
}
210210
}
211211

212+
public static File constructFileByDirectoryAndName(String directory, String fileName) {
213+
return new File(directory, fileName);
214+
}
215+
212216
/**
213217
* Creates a temporary file at the provided path.
214218
*
@@ -235,6 +239,10 @@ public static InputStream getInputStreamForFile(String path) throws IOException
235239
return Files.newInputStream(Paths.get(path));
236240
}
237241

242+
public static OutputStream getFileOutputStream(String path) throws IOException {
243+
return Files.newOutputStream(Paths.get(path));
244+
}
245+
238246
public static RandomAccessFile getRandomAccessFile(File tempFile) throws FileNotFoundException {
239247
return new RandomAccessFile(tempFile, "rw");
240248
}

0 commit comments

Comments
 (0)