Skip to content

Commit 8b4d0ca

Browse files
ars18wrwUbuntu
authored andcommitted
Cover some of commons functionality with documentation
DEVSIX-6382
1 parent 0f3f55f commit 8b4d0ca

File tree

6 files changed

+99
-3
lines changed

6 files changed

+99
-3
lines changed

commons/src/main/java/com/itextpdf/commons/actions/NamespaceConstant.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ This file is part of the iText (R) project.
4747
import java.util.Collections;
4848
import java.util.List;
4949

50+
/**
51+
* Class that stores namespaces of iText open source products.
52+
*/
5053
public final class NamespaceConstant {
5154

5255
public static final String ITEXT = "com.itextpdf";

commons/src/main/java/com/itextpdf/commons/actions/contexts/AbstractContextManagerConfigurationEvent.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,21 @@ protected AbstractContextManagerConfigurationEvent() {
3737
super();
3838
}
3939

40+
/**
41+
* Registers generic context for products and namespaces which are associated with them.
42+
*
43+
* @param namespaces namespaces of the products to be registered
44+
* @param products the products to be registered
45+
*/
4046
protected void registerGenericContext(Collection<String> namespaces, Collection<String> products) {
4147
ContextManager.getInstance().registerGenericContext(namespaces, products);
4248
}
4349

50+
/**
51+
* Unregisters certain namespaces.
52+
*
53+
* @param namespaces the namespaces to be unregisted
54+
*/
4455
protected void unregisterContext(Collection<String> namespaces) {
4556
ContextManager.getInstance().unregisterContext(namespaces);
4657
}

commons/src/main/java/com/itextpdf/commons/actions/contexts/UnknownContext.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ public class UnknownContext implements IContext {
6161

6262
private final boolean allowEvents;
6363

64+
/**
65+
* Creates a fallback {@link IContext}.
66+
*
67+
* @param allowEvents defines whether the context allows all events or not
68+
*/
6469
public UnknownContext(boolean allowEvents) {
6570
this.allowEvents = allowEvents;
6671
}

commons/src/main/java/com/itextpdf/commons/actions/processors/AbstractITextProductEventProcessor.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,18 @@ This file is part of the iText (R) project.
2525
import com.itextpdf.commons.actions.AbstractProductProcessITextEvent;
2626
import com.itextpdf.commons.exceptions.CommonsExceptionMessageConstant;
2727

28+
/**
29+
* Abstract class with some standard functionality for product event processing.
30+
*/
2831
public abstract class AbstractITextProductEventProcessor implements ITextProductEventProcessor {
2932

3033
private final String productName;
3134

35+
/**
36+
* Creates a new instance of an abstract processor for the provided product.
37+
*
38+
* @param productName the product which will be handled by this processor
39+
*/
3240
public AbstractITextProductEventProcessor(String productName) {
3341
if (productName == null) {
3442
throw new IllegalArgumentException(CommonsExceptionMessageConstant.PRODUCT_NAME_CAN_NOT_BE_NULL);

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,19 @@ This file is part of the iText (R) project.
5858
public final class EncodingUtil {
5959
private static final String UTF8 = "UTF-8";
6060

61-
62-
6361
private EncodingUtil() {
6462
}
6563

64+
/**
65+
* Converts to byte array an array of chars, taking the provided encoding into account.
66+
*
67+
* @param chars an array of chars to be converted to bytes
68+
* @param encoding the encoding to be taken into account while converting the provided array of chars
69+
*
70+
* @return the resultant array of bytes
71+
*
72+
* @throws CharacterCodingException if anything goes wrong while encoding
73+
*/
6674
public static byte[] convertToBytes(char[] chars, String encoding) throws CharacterCodingException {
6775
Charset cc = Charset.forName(encoding);
6876
CharsetEncoder ce = cc.newEncoder();
@@ -81,6 +89,16 @@ public static byte[] convertToBytes(char[] chars, String encoding) throws Charac
8189
return br;
8290
}
8391

92+
/**
93+
* Converts to String an array of bytes, taking the provided encoding into account.
94+
*
95+
* @param bytes an array of bytes to be converted to String
96+
* @param encoding the encoding to be taken into account while converting the provided bytes
97+
*
98+
* @return the resultant string
99+
*
100+
* @throws UnsupportedEncodingException if anything goes wrong while encoding
101+
*/
84102
public static String convertToString(byte[] bytes, String encoding) throws UnsupportedEncodingException {
85103
if (bytes[0] == (byte) 0xEF && bytes[1] == (byte) 0xBB
86104
&& bytes[2] == (byte) 0xBF && encoding.equals(EncodingUtil.UTF8)) {

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

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ public final class FileUtil {
7878
private FileUtil() {
7979
}
8080

81+
/**
82+
* Gets the default windows font directory.
83+
*
84+
* @return the default windows font directory
85+
*/
8186
public static String getFontsDir() {
8287
try {
8388
String winDir = System.getenv("windir");
@@ -90,6 +95,13 @@ public static String getFontsDir() {
9095
}
9196
}
9297

98+
/**
99+
* Checks whether there is a file at the provided path.
100+
*
101+
* @param path the path to the file to be checked on existence
102+
*
103+
* @return {@code true} if such a file exists, otherwise {@code false}
104+
*/
93105
public static boolean fileExists(String path) {
94106
if (path != null) {
95107
File f = new File(path);
@@ -98,6 +110,14 @@ public static boolean fileExists(String path) {
98110
return false;
99111
}
100112

113+
/**
114+
* Checks whether there is a directory at the provided path.
115+
*
116+
* @param path the path to the directory to be checked on existence
117+
*
118+
* @return {@code true} if such a directory exists, otherwise {@code false}
119+
*/
120+
101121
public static boolean directoryExists(String path) {
102122
if (path != null) {
103123
File f = new File(path);
@@ -106,6 +126,14 @@ public static boolean directoryExists(String path) {
106126
return false;
107127
}
108128

129+
/**
130+
* Lists all the files located at the provided directory.
131+
*
132+
* @param path path to the directory
133+
* @param recursive if {@code true}, files from all the subdirectories will be returned
134+
*
135+
* @return all the files located at the provided directory
136+
*/
109137
public static String[] listFilesInDirectory(String path, boolean recursive) {
110138
if (path != null) {
111139
File root = new File(path);
@@ -129,6 +157,14 @@ public static String[] listFilesInDirectory(String path, boolean recursive) {
129157
return null;
130158
}
131159

160+
/**
161+
* Lists all the files located at the provided directory, which are accepted by the provided filter.
162+
*
163+
* @param outPath path to the directory
164+
* @param fileFilter filter to accept files to be listed
165+
*
166+
* @return all the files located at the provided directory, which are accepted by the provided filter
167+
*/
132168
public static File[] listFilesInDirectoryByFilter(String outPath, FileFilter fileFilter) {
133169
File[] result = null;
134170
if (outPath != null && !outPath.isEmpty()) {
@@ -173,6 +209,16 @@ public static java.io.OutputStream wrapWithBufferedOutputStream(OutputStream out
173209
}
174210
}
175211

212+
/**
213+
* Creates a temporary file at the provided path.
214+
*
215+
* @param path path to the temporary file to be created. If it is a directory, then the temporary file
216+
* will be created at this directory
217+
*
218+
* @return the created temporary file
219+
*
220+
* @throws IOException signals that an I/O exception has occurred
221+
*/
176222
public static File createTempFile(String path) throws IOException {
177223
File tempFile = new File(path);
178224
if (tempFile.isDirectory()) {
@@ -193,6 +239,11 @@ public static RandomAccessFile getRandomAccessFile(File tempFile) throws FileNot
193239
return new RandomAccessFile(tempFile, "rw");
194240
}
195241

242+
/**
243+
* Creates a directory at the provided path.
244+
*
245+
* @param outPath path to the directory to be created
246+
*/
196247
public static void createDirectories(String outPath) {
197248
new File(outPath).mkdirs();
198249
}
@@ -298,7 +349,7 @@ public static String createTempDirectory(String tempFilePrefix)
298349
*
299350
* @param paths paths to files, which should be removed
300351
*
301-
* @return true if all the files have been successfully removed, false otherwise
352+
* @return {@code true} if all the files have been successfully removed, {@code false} otherwise
302353
*/
303354
public static boolean removeFiles(String[] paths) {
304355
boolean allFilesAreRemoved = true;

0 commit comments

Comments
 (0)