本文整理匯總了Java中java.nio.charset.Charset.decode方法的典型用法代碼示例。如果您正苦於以下問題:Java Charset.decode方法的具體用法?Java Charset.decode怎麽用?Java Charset.decode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.nio.charset.Charset
的用法示例。
在下文中一共展示了Charset.decode方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: decode
import java.nio.charset.Charset; //導入方法依賴的package包/類
public void decode() throws MAPException {
if (this.isDecoded)
return;
this.isDecoded = true;
this.decodedMessage = null;
if (this.encodedData == null)
throw new MAPException("Error decoding a text from Sms CommandData: encodedData field is null");
// TODO: what is an encoding algorithm ?
Charset chs = Charset.forName("US-ASCII");
byte[] buf = this.encodedData;
ByteBuffer bb = ByteBuffer.wrap(buf);
CharBuffer bf = chs.decode(bb);
this.decodedMessage = bf.toString();
}
示例2: getCharSequence
import java.nio.charset.Charset; //導入方法依賴的package包/類
/**
* Converts an input file stream into a char sequence.
*
* @throws IOException
*/
static CharBuffer getCharSequence(final FileInputStream stream, Charset encoding) throws IOException {
FileChannel channel = stream.getChannel();
ByteBuffer bbuf = ByteBuffer.allocate((int) channel.size());
try {
channel.read(bbuf, 0);
} catch (ClosedByInterruptException cbie) {
return null; //this is actually okay
} finally {
channel.close();
}
bbuf.rewind();
CharBuffer cbuf = encoding.decode(bbuf);
return cbuf;
}
示例3: run
import java.nio.charset.Charset; //導入方法依賴的package包/類
public void run() {
while (true) {
try {
mChannel.read(mReceiveBuf);
mReceiveBuf.flip();
Charset charset = Charset.forName("ASCII");
CharBuffer cbuf = charset.decode(mReceiveBuf);
String result = cbuf.toString();
parseAndCallback(result);
mReceiveBuf.clear();
} catch (Exception e) {
disconnect();
//TODO: implement some handling here!
break;
}
}
}
示例4: decode
import java.nio.charset.Charset; //導入方法依賴的package包/類
/**
* Convert string from UTF-7 characters
*
* @param string Input string for decoding
* @return Decoded string
*/
public static String decode(String string, String charsetName)
{
if (string.length() <= 1)
{
return string;
}
CharsetProvider provider = new CharsetProvider();
Charset charset = provider.charsetForName(charsetName);
CharBuffer charBuffer = charset.decode(ByteBuffer.wrap(string.getBytes()));
return charBuffer.toString();
}
示例5: convert
import java.nio.charset.Charset; //導入方法依賴的package包/類
protected static Object convert ( final byte[] data, final Charset charset )
{
if ( data == null )
{
return null;
}
if ( charset == null )
{
return data;
}
final CharBuffer cb = charset.decode ( ByteBuffer.wrap ( data ) );
return cb.toString ();
}
示例6: toString
import java.nio.charset.Charset; //導入方法依賴的package包/類
/** Consumes remaining contents of this object, and returns them as a string. */
public String toString() {
Charset cset = Charset.forName("UTF-8");
CharBuffer cb = cset.decode(ByteBuffer.wrap(this.toArray()));
return cb.toString();
}