Release 1.6.0 of Norconex Commons Lang provides new Java utility classes and enhancements to existing ones:
New Classes
TimeIdGenerator
[ezcol_1half]
Use TimeIdGenerator
when you need to generate numeric IDs that are unique within a JVM. It generates Java long values that are guaranteed to be in order (but can have gaps). Can generate up to 1 million unique IDs per milliseconds. Read Javadoc.
[/ezcol_1half]
[ezcol_1half_end]
long id = 0; id = TimeIdGenerator.next(); System.out.println(id); // prints 1427256596604000000 id = TimeIdGenerator.last(); System.out.println(id); // prints 1427256596604000000 id = TimeIdGenerator.next(); System.out.println(id); // prints 1427256596604000001
[/ezcol_1half_end]
TextReader
[ezcol_1half]
A new class for reading large text, one chunk at a time, based on a specified maximum read size. When a text is too large, it tries to split it wisely at each paragraphs, sentences, or words (whichever one is possible). Read Javadoc.
[/ezcol_1half]
[ezcol_1half_end]
// Process maximum 500KB at a time TextReader reader = new TextReader(originalReader, 500 * 1024); String textChunk = null; while ((textChunk = reader.readText()) != null) { // do something with textChunk } reader.close();
[/ezcol_1half_end]
ByteArrayOutputStream
[ezcol_1half]
An alternate version of Java and Apache Commons ByteArrayOutputStream
. Like the Apache version, this version is faster than Java ByteArrayOutputStream
. In addition, it provides additional methods for obtaining a subset of bytes ranging from zero to the total number of bytes written so far. Read Javadoc.
[/ezcol_1half]
[ezcol_1half_end]
ByteArrayOutputStream out = new ByteArrayOutputStream(); out.write("ABCDE".getBytes()); out.write("FGHIJKLMNOPQRSTUVWXYZ".getBytes()); byte[] b = new byte[10]; out.getBytes(b, 0); System.out.println(new String(b)); // prints ABCDEFGHIJ System.out.println((char) out.getByte(15)); // prints P
[/ezcol_1half_end]
Enhancements
IOUtil enhancements
The following utility methods were added to the IOUtil
class:
IOUtil#toBufferedReader(Reader)
returns either aBufferedReader
wrapping an original reader, or the reader itself if it already implementsBufferedReader
.IOUtil#toBufferedInputStream(InputStream)
returns either aBufferedInputStream
wrapping an original reader, or the reader itself if it already implements BufferedInputStream.IOUtil#startsWith(InputStream, byte[])
returns true if the given input stream starts with the specified byte array.IOUtil#borrowBytes(InputStream, int)
gets and resets the specified number of bytes from the input stream. It must supportmark(int)
.
Other improvements
CachedInputSream
now supportsmark(int)
. Mark value is always unlimited (argument is ignored).ContentType
andContentFamily
now support BIG2 and Quattro Pro file formats.
Get your copy
Download Norconex Commons Lang 1.6.0.
You can also view the release notes for a complete list of changes.