public abstract class AbstractCharactersetFinder extends java.lang.Object implements CharactersetFinder
| Constructor and Description |
|---|
AbstractCharactersetFinder() |
| Modifier and Type | Method and Description |
|---|---|
java.nio.charset.Charset |
detectCharset(byte[] buffer)
Attempt to detect the character set encoding for the given buffer.
|
java.nio.charset.Charset |
detectCharset(java.io.InputStream is)
Attempt to detect the character set encoding for the give input stream.
|
protected abstract java.nio.charset.Charset |
detectCharsetImpl(byte[] buffer)
Worker method for implementations to override.
|
protected int |
getBufferSize()
Some implementations may only require a few bytes to do detect the stream type,
whilst others may be more efficient with larger buffers.
|
void |
setBufferSize(int bufferSize)
Set the maximum number of bytes to read ahead when attempting to determine the characterset.
|
public void setBufferSize(int bufferSize)
bufferSize - the number of bytes - default 8K.public final java.nio.charset.Charset detectCharset(java.io.InputStream is)
BufferedInputStream.
The current state of the stream will be restored before the method returns.
The input stream is checked to ensure that it supports marks, after which a buffer is extracted, leaving the stream in its original state.
detectCharset in interface CharactersetFinderis - an input stream that must support markingpublic final java.nio.charset.Charset detectCharset(byte[] buffer)
CharactersetFinderdetectCharset in interface CharactersetFinderbuffer - the first n bytes of the character streamprotected int getBufferSize()
Only override this method if there is a very compelling reason to adjust the buffer
size, and then consider handling the AbstractCharactersetFinder.setBufferSize(int) method by issuing a
warning. This will prevent users from setting the buffer size when it has no effect.
CharactersetFinder.detectCharset(byte[]) method.AbstractCharactersetFinder.setBufferSize(int)protected abstract java.nio.charset.Charset detectCharsetImpl(byte[] buffer)
throws java.lang.Exception
The interface contract is that the data buffer must not be altered in any way.
buffer - the buffer of data no bigger than the requested
best buffer size. This can,
very efficiently, be turned into an InputStream using a
ByteArrayInputStream.java.lang.Exception - Any exception, checked or notCopyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.