encodingmanager.java
来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 532 行 · 第 1/2 页
JAVA
532 行
public static Decoder getDecoder() {
return (default_decoder_instance);
}
/*************************************************************************/
/**
* This method returns the default instance of the <code>Decoder</code>
* for the named encoding. This must be used only for calling the static
* byte array conversion methods. Calling any instance methods on this
* object will result in a <code>NullPointerException</code>
*
* This form of <code>getDecoder</code> caches the instance that is returned. If
* this decoder is for a complex character encoding that may use lots of
* memory and is only needed once or infrequently, consider using the form
* of the <code>getDecoder</code> method that does not cache the results
* to save resources.
*
* @param encoding The name of the encoding to retrieve a <code>Decoder</code> for.
*
* @return An instance of the <code>Decoder</code> for the named encoding.
*
* @exception UnsupportedEncodingException If a <code>Decoder</code> for the named encoding cannot be found
*/
public static Decoder getDecoder(String encoding) throws UnsupportedEncodingException {
return (getDecoder(encoding, true));
}
/*************************************************************************/
/**
* This method returns the default instance of the <code>Decoder</code>
* for the named encoding. This must be used only for calling the static
* byte array conversion methods. Calling any instance methods on this
* object will result in a <code>NullPointerException</code>
*
* @param encoding The name of the encoding to retrieve a <code>Decoder</code> for.
* @param cache <code>true</code> to cache this encoding, <code>false</code> otherwise
*
* @return An instance of the <code>Decoder</code> for the named encoding.
*
* @exception UnsupportedEncodingException If a <code>Decoder</code> for the named encoding cannot be found
*/
public static Decoder getDecoder(String encoding, boolean cache) throws UnsupportedEncodingException {
Decoder dec = (Decoder) decoder_instances.get(encoding);
if (dec != null)
return (dec);
dec = getDecoder(null, encoding, cache);
if (cache)
decoder_instances.put(encoding, dec);
return (dec);
}
/*************************************************************************/
/**
* This method returns a <code>Decoder</code> object that can read
* from the specified <code>InputStream</code> using the default
* encoding.
*
* @param in The <code>InputStream</code> to read from
*/
public static Decoder getDecoder(InputStream in) {
Object[] params = new Object[1];
params[0] = in;
Decoder dec = null;
try {
dec = (Decoder) default_decoder_cons.newInstance(params);
} catch (Exception e) {
throw new Error("Unexpected problems with default decoder");
}
return (dec);
}
/*************************************************************************/
/**
* This method returns a <code>Decoder</code> object that can read from
* the specified <code>InputStream</code> using the named encoding
*
* This form of <code>getDecoder</code> caches the instance that is returned. If
* this decoder is for a complex character encoding that may use lots of
* memory and is only needed once or infrequently, consider using the form
* of the <code>getDecoder</code> method that does not cache the results
* to save resources.
*
* @param in The <code>InputStream</code> to read from
* @param encoding The name of the character encoding scheme to use
*
* @exception UnsupportedEncodingException If a <code>Decoder</code> for this encoding cannot be found
*/
public static Decoder getDecoder(InputStream in, String encoding) throws UnsupportedEncodingException {
return (getDecoder(in, encoding, true));
}
/*************************************************************************/
/**
* This method returns a <code>Decoder</code> object that can read from
* the specified <code>InputStream</code> using the named encoding
*
* @param in The <code>InputStream</code> to read from
* @param encoding The name of the character encoding scheme to use
* @param cache <code>true</code> to cache the returned <code>Decoder</code>, <code>false</code> otherwise.
*
* @exception UnsupportedEncodingException If a <code>Decoder</code> for this encoding cannot be found
*/
public static Decoder getDecoder(InputStream in, String encoding, boolean cache) throws UnsupportedEncodingException {
Constructor cons = findDecoderConstructor(encoding, cache);
Object[] params = new Object[1];
params[0] = in;
Decoder dec = null;
try {
dec = (Decoder) cons.newInstance(params);
} catch (Exception e) {
throw new UnsupportedEncodingException(encoding + ": " + e.getMessage());
}
return (dec);
}
/*************************************************************************/
/**
* This method returns the default instance of the default <code>Encoder</code>
* which must be used only for calling the static byte array conversion methods.
* Calling any instance methods on this object will result in a
* <code>NullPointerException</code>.
*
* @return An instance of the default <code>Encoder</code>.
*/
public static Encoder getEncoder() {
return (default_encoder_instance);
}
/*************************************************************************/
/**
* This method returns the default instance of the <code>Encoder</code>
* for the named encoding. This must be used only for calling the static
* byte array conversion methods. Calling any instance methods on this
* object will result in a <code>NullPointerException</code>
*
* This form of <code>getEncoder</code> caches the instance that is returned. If
* this decoder is for a complex character encoding that may use lots of
* memory and is only needed once or infrequently, consider using the form
* of the <code>getEncoder</code> method that does not cache the results
* to save resources.
*
* @param encoding The name of the encoding to retrieve a <code>Encoder</code> for.
*
* @return An instance of the <code>Encoder</code> for the named encoding.
*
* @exception UnsupportedEncodingException If a <code>Encoder</code> for the named encoding cannot be found
*/
public static Encoder getEncoder(String encoding) throws UnsupportedEncodingException {
return (getEncoder(encoding, true));
}
/*************************************************************************/
/**
* This method returns the default instance of the <code>Encoder</code>
* for the named encoding. This must be used only for calling the static
* byte array conversion methods. Calling any instance methods on this
* object will result in a <code>NullPointerException</code>
*
* @param encoding The name of the encoding to retrieve a <code>Encoder</code> for.
* @param cache <code>true</code> to cache this encoding, <code>false</code> otherwise
*
* @return An instance of the <code>Encoder</code> for the named encoding.
*
* @exception UnsupportedEncodingException If a <code>Encoder</code> for the named encoding cannot be found
*/
public static Encoder getEncoder(String encoding, boolean cache) throws UnsupportedEncodingException {
Encoder enc = (Encoder) encoder_instances.get(encoding);
if (enc != null)
return (enc);
enc = getEncoder(null, encoding, cache);
if (cache)
encoder_instances.put(encoding, enc);
return (enc);
}
/*************************************************************************/
/**
* This method returns an <code>Encoder</code> object that can write
* to the specified <code>OutputStream</code> using the default
* encoding.
*
* @param out The <code>OutputStream</code> to read from
*/
public static Encoder getEncoder(OutputStream out) {
Object[] params = new Object[1];
params[0] = out;
Encoder enc = null;
try {
enc = (Encoder) default_encoder_cons.newInstance(params);
} catch (Exception e) {
throw new Error("Unexpected problems with default decoder");
}
return (enc);
}
/*************************************************************************/
/**
* This method returns an <code>Encoder</code> object that can write to
* the specified <code>OutputStream</code> using the named encoding
*
* This form of <code>getencoder</code> caches the instance that is returned. If
* this encoder is for a complex character encoding that may use lots of
* memory and is only needed once or infrequently, consider using the form
* of the <code>getEncoder</code> method that does not cache the results
* to save resources.
*
* @param in The <code>OutputStream</code> to read from
* @param encoding The name of the character encoding scheme to use
*
* @exception UnsupportedEncodingException If an <code>Encoder</code> for this encoding cannot be found
*/
public static Encoder getEncoder(OutputStream in, String encoding) throws UnsupportedEncodingException {
return (getEncoder(in, encoding, true));
}
/*************************************************************************/
/**
* This method returns an <code>Encoder</code> object that can write to
* the specified <code>OutputStream</code> using the named encoding
*
* @param in The <code>OutputStream</code> to read from
* @param encoding The name of the character encoding scheme to use
* @param cache <code>true</code> to cache the returned <code>Encoder</code>, <code>false</code> otherwise.
*
* @exception UnsupportedEncodingException If a <code>Decoder</code> for this encoding cannot be found
*/
public static Encoder getEncoder(OutputStream out, String encoding, boolean cache) throws UnsupportedEncodingException {
Constructor cons = findEncoderConstructor(encoding, cache);
Object[] params = new Object[1];
params[0] = out;
Encoder enc = null;
try {
enc = (Encoder) cons.newInstance(params);
} catch (Exception e) {
throw new UnsupportedEncodingException(encoding + ": " + e.getMessage());
}
return (enc);
}
} // class EncodingManager
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?