本文整理汇总了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();
}