Skip to content

Commit a976571

Browse files
committed
Cover some of commons functionality with documentation
DEVSIX-6382 Autoported commit. Original commit hash: [8b4d0ca] Manual files: commons/src/main/java/com/itextpdf/commons/actions/NamespaceConstant.java commons/src/main/java/com/itextpdf/commons/utils/EncodingUtil.java commons/src/main/java/com/itextpdf/commons/utils/FileUtil.java
1 parent e4d00b9 commit a976571

File tree

7 files changed

+70
-1
lines changed

7 files changed

+70
-1
lines changed

itext/itext.commons/itext/commons/actions/NamespaceConstant.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ source product.
4646
using iText.Commons.Utils;
4747

4848
namespace iText.Commons.Actions {
49+
/// <summary>Class that stores namespaces of iText open source products.</summary>
4950
public sealed class NamespaceConstant {
5051
public const String ITEXT = "iText";
5152

itext/itext.commons/itext/commons/actions/contexts/AbstractContextManagerConfigurationEvent.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,16 @@ protected internal AbstractContextManagerConfigurationEvent()
3333
: base() {
3434
}
3535

36+
/// <summary>Registers generic context for products and namespaces which are associated with them.</summary>
37+
/// <param name="namespaces">namespaces of the products to be registered</param>
38+
/// <param name="products">the products to be registered</param>
3639
protected internal virtual void RegisterGenericContext(ICollection<String> namespaces, ICollection<String>
3740
products) {
3841
ContextManager.GetInstance().RegisterGenericContext(namespaces, products);
3942
}
4043

44+
/// <summary>Unregisters certain namespaces.</summary>
45+
/// <param name="namespaces">the namespaces to be unregisted</param>
4146
protected internal virtual void UnregisterContext(ICollection<String> namespaces) {
4247
ContextManager.GetInstance().UnregisterContext(namespaces);
4348
}

itext/itext.commons/itext/commons/actions/contexts/UnknownContext.cs

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

6666
private readonly bool allowEvents;
6767

68+
/// <summary>
69+
/// Creates a fallback
70+
/// <see cref="IContext"/>.
71+
/// </summary>
72+
/// <param name="allowEvents">defines whether the context allows all events or not</param>
6873
public UnknownContext(bool allowEvents) {
6974
this.allowEvents = allowEvents;
7075
}

itext/itext.commons/itext/commons/actions/processors/AbstractITextProductEventProcessor.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ You should have received a copy of the GNU Affero General Public License
2525
using iText.Commons.Exceptions;
2626

2727
namespace iText.Commons.Actions.Processors {
28+
/// <summary>Abstract class with some standard functionality for product event processing.</summary>
2829
public abstract class AbstractITextProductEventProcessor : ITextProductEventProcessor {
2930
private readonly String productName;
3031

32+
/// <summary>Creates a new instance of an abstract processor for the provided product.</summary>
33+
/// <param name="productName">the product which will be handled by this processor</param>
3134
public AbstractITextProductEventProcessor(String productName) {
3235
if (productName == null) {
3336
throw new ArgumentException(CommonsExceptionMessageConstant.PRODUCT_NAME_CAN_NOT_BE_NULL);

itext/itext.commons/itext/commons/utils/EncodingUtil.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ static EncodingUtil() {
6161

6262
public static Encoding ISO_8859_1 = EncodingUtil.GetEncoding("ISO-8859-1");
6363

64+
/// <summary>
65+
/// Converts to byte array an array of chars, taking the provided encoding into account.
66+
/// </summary>
67+
/// <param name="chars">an array of chars to be converted to bytes</param>
68+
/// <param name="encoding">the encoding to be taken into account while converting the provided array of chars</param>
69+
/// <returns>the resultant array of bytes</returns>
6470
public static byte[] ConvertToBytes(char[] chars, String encoding) {
6571
Encoding encw = IanaEncodings.GetEncodingEncoding(encoding);
6672
byte[] preamble = encw.GetPreamble();
@@ -75,6 +81,12 @@ public static byte[] ConvertToBytes(char[] chars, String encoding) {
7581
}
7682
}
7783

84+
/// <summary>
85+
/// Converts to String an array of bytes, taking the provided encoding into account.
86+
/// </summary>
87+
/// <param name="chars">an array of bytes to be converted to String</param>
88+
/// <param name="encoding">the encoding to be taken into account while converting the provided bytes</param>
89+
/// <returns>the resultant string</returns>
7890
public static String ConvertToString(byte[] bytes, String encoding) {
7991
if (encoding.Equals(EncodingUtil.UTF8) &&
8092
bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF)

itext/itext.commons/itext/commons/utils/FileUtil.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,45 @@ namespace iText.Commons.Utils {
5656
public static class FileUtil {
5757
private static int tempFileCounter = 0;
5858

59+
/// <summary>
60+
/// Gets the default windows font directory.
61+
/// </summary>
62+
/// <returns>the default windows font directory</returns>
5963
public static String GetFontsDir() {
6064
String windir = Environment.GetEnvironmentVariable("windir");
6165
return windir != null ? Path.Combine(windir, "fonts") : "";
6266
}
6367

68+
/// <summary>
69+
/// Checks whether there is a file at the provided path.
70+
/// </summary>
71+
/// <param name="path">the path to the file to be checked on existence</param>
72+
/// <returns><CODE>true</CODE> if such a file exists, otherwise <CODE>false</CODE></returns>
6473
public static bool FileExists(String path) {
6574
if (!String.IsNullOrEmpty(path)) {
6675
return new FileInfo(path).Exists;
6776
}
6877
return false;
6978
}
7079

80+
/// <summary>
81+
/// Checks whether there is a directory at the provided path.
82+
/// </summary>
83+
/// <param name="path">the path to the directory to be checked on existence</param>
84+
/// <returns>true if such a directory exists, otherwise false</returns>
7185
public static bool DirectoryExists(String path) {
7286
if (!String.IsNullOrEmpty(path)) {
7387
return new DirectoryInfo(path).Exists;
7488
}
7589
return false;
7690
}
7791

92+
/// <summary>
93+
/// Lists all the files located at the provided directory.
94+
/// </summary>
95+
/// <param name="path">path to the directory</param>
96+
/// <param name="recursive">if <CODE>true</CODE>, files from all the subdirectories will be returned</param>
97+
/// <returns>all the files located at the provided directory</returns>
7898
public static String[] ListFilesInDirectory(String path, bool recursive) {
7999
if (!String.IsNullOrEmpty(path)) {
80100
DirectoryInfo dir = new DirectoryInfo(path);
@@ -92,10 +112,23 @@ public static String[] ListFilesInDirectory(String path, bool recursive) {
92112
return null;
93113
}
94114

115+
/// <summary>
116+
/// Lists all the files located at the provided directory, which are accepted by the provided filter.
117+
/// </summary>
118+
/// <param name="path">path to the directory</param>
119+
/// <param name="filter">filter to accept files to be listed</param>
120+
/// <returns>all the files located at the provided directory, which are accepted by the provided filter</returns>
95121
public static FileInfo[] ListFilesInDirectoryByFilter(String path, IFileFilter filter) {
96122
return ListFilesInDirectoryByFilter(path, false, filter);
97123
}
98124

125+
/// <summary>
126+
/// Lists all the files located at the provided directory, which are accepted by the provided filter.
127+
/// </summary>
128+
/// <param name="path">path to the directory</param>
129+
/// <param name="recursive">if <CODE>true</CODE>, files from all the subdirectories will be returned</param>
130+
/// <param name="filter">filter to accept files to be listed</param>
131+
/// <returns>all the files located at the provided directory, which are accepted by the provided filter</returns>
99132
public static FileInfo[] ListFilesInDirectoryByFilter(String path, bool recursive, IFileFilter filter) {
100133
if (!String.IsNullOrEmpty(path)) {
101134
DirectoryInfo dir = new DirectoryInfo(path);
@@ -123,6 +156,12 @@ public static Stream GetBufferedOutputStream(String filename) {
123156
return new FileStream(filename, FileMode.Create);
124157
}
125158

159+
/// <summary>
160+
/// Creates a temporary file at the provided path.
161+
/// </summary>
162+
/// <param name="path">path to the temporary file to be created. If it is a directory,
163+
/// then the temporary file will be created at this directory</param>
164+
/// <returns>the created temporary file</returns>
126165
public static FileInfo CreateTempFile(String path) {
127166
if (DirectoryExists(path)) {
128167
return new FileInfo(path + Path.DirectorySeparatorChar + "pdf_" + Interlocked.Increment(ref tempFileCounter));
@@ -148,6 +187,10 @@ public static Stream WrapWithBufferedOutputStream(Stream outputStream)
148187
return outputStream;
149188
}
150189

190+
/// <summary>
191+
/// Creates a directory at the provided path.
192+
/// </summary>
193+
/// <param name="outPath">path to the directory to be created</param>
151194
public static void CreateDirectories(String outPath) {
152195
Directory.CreateDirectory(outPath);
153196
}

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0f3f55f35ec6f902330696262c7237135d44bf86
1+
8b4d0ca65f67858c609e5ee542119afff3329d51

0 commit comments

Comments
 (0)