当前位置: 首页>>代码示例>>Java>>正文


Java CoderResult.toString方法代码示例

本文整理汇总了Java中java.nio.charset.CoderResult.toString方法的典型用法代码示例。如果您正苦于以下问题:Java CoderResult.toString方法的具体用法?Java CoderResult.toString怎么用?Java CoderResult.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.charset.CoderResult的用法示例。


在下文中一共展示了CoderResult.toString方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getBytes

import java.nio.charset.CoderResult; //导入方法依赖的package包/类
byte[] getBytes(String s) {
    CharsetEncoder ce = encoder().reset();
    char[] ca = s.toCharArray();
    int len = (int)(ca.length * ce.maxBytesPerChar());
    byte[] ba = new byte[len];
    if (len == 0)
        return ba;
    ByteBuffer bb = ByteBuffer.wrap(ba);
    CharBuffer cb = CharBuffer.wrap(ca);
    CoderResult cr = ce.encode(cb, bb, true);
    if (!cr.isUnderflow())
        throw new IllegalArgumentException(cr.toString());
    cr = ce.flush(bb);
    if (!cr.isUnderflow())
        throw new IllegalArgumentException(cr.toString());
    if (bb.position() == ba.length)  // defensive copy?
        return ba;
    else
        return Arrays.copyOf(ba, bb.position());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:ZipCoder.java

示例2: flush

import java.nio.charset.CoderResult; //导入方法依赖的package包/类
public void flush() throws IOException {
    //Log.i("PackageManager", "flush mPos=" + mPos);
    if (mPos > 0) {
        if (mOutputStream != null) {
            CharBuffer charBuffer = CharBuffer.wrap(mText, 0, mPos);
            CoderResult result = mCharset.encode(charBuffer, mBytes, true);
            while (true) {
                if (result.isError()) {
                    throw new IOException(result.toString());
                } else if (result.isOverflow()) {
                    flushBytes();
                    result = mCharset.encode(charBuffer, mBytes, true);
                    continue;
                }
                break;
            }
            flushBytes();
            mOutputStream.flush();
        } else {
            mWriter.write(mText, 0, mPos);
            mWriter.flush();
        }
        mPos = 0;
    }
}
 
开发者ID:7763sea,项目名称:VirtualHook,代码行数:26,代码来源:FastXmlSerializer.java

示例3: toString

import java.nio.charset.CoderResult; //导入方法依赖的package包/类
String toString(byte[] ba, int length) {
    CharsetDecoder cd = decoder().reset();
    int len = (int)(length * cd.maxCharsPerByte());
    char[] ca = new char[len];
    if (len == 0)
        return new String(ca);
    ByteBuffer bb = ByteBuffer.wrap(ba, 0, length);
    CharBuffer cb = CharBuffer.wrap(ca);
    CoderResult cr = cd.decode(bb, cb, true);
    if (!cr.isUnderflow())
        throw new IllegalArgumentException(cr.toString());
    cr = cd.flush(cb);
    if (!cr.isUnderflow())
        throw new IllegalArgumentException(cr.toString());
    return new String(ca, 0, cb.position());
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:ZipCoder.java

示例4: toString

import java.nio.charset.CoderResult; //导入方法依赖的package包/类
String toString(byte[] ba, int length) {
    CharsetDecoder cd = decoder().reset();
    int len = (int)(length * cd.maxCharsPerByte());
    char[] ca = new char[len];
    if (len == 0)
        return new String(ca);
    // UTF-8 only for now. Other ArrayDeocder only handles
    // CodingErrorAction.REPLACE mode. ZipCoder uses
    // REPORT mode.
    if (isUTF8 && cd instanceof ArrayDecoder) {
        int clen = ((ArrayDecoder)cd).decode(ba, 0, length, ca);
        if (clen == -1)    // malformed
            throw new IllegalArgumentException("MALFORMED");
        return new String(ca, 0, clen);
    }
    ByteBuffer bb = ByteBuffer.wrap(ba, 0, length);
    CharBuffer cb = CharBuffer.wrap(ca);
    CoderResult cr = cd.decode(bb, cb, true);
    if (!cr.isUnderflow())
        throw new IllegalArgumentException(cr.toString());
    cr = cd.flush(cb);
    if (!cr.isUnderflow())
        throw new IllegalArgumentException(cr.toString());
    return new String(ca, 0, cb.position());
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:26,代码来源:ZipCoder.java

示例5: toString

import java.nio.charset.CoderResult; //导入方法依赖的package包/类
String toString(byte[] ba, int off, int length) {
    CharsetDecoder cd = decoder().reset();
    int len = (int)(length * cd.maxCharsPerByte());
    char[] ca = new char[len];
    if (len == 0)
        return new String(ca);
    // UTF-8 only for now. Other ArrayDeocder only handles
    // CodingErrorAction.REPLACE mode. ZipCoder uses
    // REPORT mode.
    if (isUTF8 && cd instanceof ArrayDecoder) {
        int clen = ((ArrayDecoder)cd).decode(ba, off, length, ca);
        if (clen == -1)    // malformed
            throw new IllegalArgumentException("MALFORMED");
        return new String(ca, 0, clen);
    }
    ByteBuffer bb = ByteBuffer.wrap(ba, off, length);
    CharBuffer cb = CharBuffer.wrap(ca);
    CoderResult cr = cd.decode(bb, cb, true);
    if (!cr.isUnderflow())
        throw new IllegalArgumentException(cr.toString());
    cr = cd.flush(cb);
    if (!cr.isUnderflow())
        throw new IllegalArgumentException(cr.toString());
    return new String(ca, 0, cb.position());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:ZipCoder.java

示例6: toString

import java.nio.charset.CoderResult; //导入方法依赖的package包/类
String toString(byte[] ba) {
    CharsetDecoder cd = decoder().reset();
    int clen = (int)(ba.length * cd.maxCharsPerByte());
    char[] ca = new char[clen];
    if (clen == 0)
        return new String(ca);
    ByteBuffer bb = ByteBuffer.wrap(ba, 0, ba.length);
    CharBuffer cb = CharBuffer.wrap(ca);
    CoderResult cr = cd.decode(bb, cb, true);
    if (!cr.isUnderflow())
        throw new IllegalArgumentException(cr.toString());
    cr = cd.flush(cb);
    if (!cr.isUnderflow())
        throw new IllegalArgumentException(cr.toString());
    return new String(ca, 0, cb.position());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:ZipCoder.java

示例7: write

import java.nio.charset.CoderResult; //导入方法依赖的package包/类
public void write() {
	buffer.clear();
	CoderResult cr = encoder.encode(message, buffer, true);
	if (cr.isError()) {
		throw new IllegalArgumentException(cr.toString());
	}
	isDone = !cr.isOverflow();
	buffer.flip();
	endpoint.startMessage(Constants.OPCODE_TEXT, buffer, isDone && isLast, this);
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:11,代码来源:WsRemoteEndpointImplBase.java

示例8: byte2char

import java.nio.charset.CoderResult; //导入方法依赖的package包/类
private void byte2char(ByteBuffer bytes, CharBuffer chars) throws IOException {
    decoder.reset();
    chars.clear();
    CoderResult result = decoder.decode(bytes, chars, true);
    if (result.isError() || result.isOverflow()) {
        throw new IOException(result.toString());
    } else if (result.isUnderflow()) {
        chars.flip();
    }
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:11,代码来源:WriterOutputStream.java

示例9: write

import java.nio.charset.CoderResult; //导入方法依赖的package包/类
public void write() {
    buffer.clear();
    CoderResult cr = encoder.encode(message, buffer, true);
    if (cr.isError()) {
        throw new IllegalArgumentException(cr.toString());
    }
    isDone = !cr.isOverflow();
    buffer.flip();
    endpoint.startMessage(Constants.OPCODE_TEXT, buffer,
            isDone && isLast, this);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:12,代码来源:WsRemoteEndpointImplBase.java

示例10: getBytes

import java.nio.charset.CoderResult; //导入方法依赖的package包/类
byte[] getBytes(String s) {
    CharsetEncoder ce = encoder().reset();
    char[] ca = s.toCharArray();
    int len = (int)(ca.length * ce.maxBytesPerChar());
    byte[] ba = new byte[len];
    if (len == 0)
        return ba;
    // UTF-8 only for now. Other ArrayDeocder only handles
    // CodingErrorAction.REPLACE mode.
    if (isUTF8 && ce instanceof ArrayEncoder) {
        int blen = ((ArrayEncoder)ce).encode(ca, 0, ca.length, ba);
        if (blen == -1)    // malformed
            throw new IllegalArgumentException("MALFORMED");
        return Arrays.copyOf(ba, blen);
    }
    ByteBuffer bb = ByteBuffer.wrap(ba);
    CharBuffer cb = CharBuffer.wrap(ca);
    CoderResult cr = ce.encode(cb, bb, true);
    if (!cr.isUnderflow())
        throw new IllegalArgumentException(cr.toString());
    cr = ce.flush(bb);
    if (!cr.isUnderflow())
        throw new IllegalArgumentException(cr.toString());
    if (bb.position() == ba.length)  // defensive copy?
        return ba;
    else
        return Arrays.copyOf(ba, bb.position());
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:29,代码来源:ZipCoder.java

示例11: flushLocked

import java.nio.charset.CoderResult; //导入方法依赖的package包/类
private void flushLocked() throws IOException {
    //Log.i("PackageManager", "flush mPos=" + mPos);
    if (mPos > 0) {
        if (mOutputStream != null) {
            CharBuffer charBuffer = CharBuffer.wrap(mText, 0, mPos);
            CoderResult result = mCharset.encode(charBuffer, mBytes, true);
            while (true) {
                if (result.isError()) {
                    throw new IOException(result.toString());
                } else if (result.isOverflow()) {
                    flushBytesLocked();
                    result = mCharset.encode(charBuffer, mBytes, true);
                    continue;
                }
                break;
            }
            flushBytesLocked();
            mOutputStream.flush();
        } else if (mWriter != null) {
            mWriter.write(mText, 0, mPos);
            mWriter.flush();
        } else {
            int nonEolOff = 0;
            final int sepLen = mSeparator.length();
            final int len = sepLen < mPos ? sepLen : mPos;
            while (nonEolOff < len && mText[mPos - 1 - nonEolOff]
                    == mSeparator.charAt(mSeparator.length() - 1 - nonEolOff)) {
                nonEolOff++;
            }
            if (nonEolOff >= mPos) {
                mPrinter.println("");
            } else {
                mPrinter.println(new String(mText, 0, mPos - nonEolOff));
            }
        }
        mPos = 0;
    }
}
 
开发者ID:lfkdsk,项目名称:Just-Evaluator,代码行数:39,代码来源:FastPrintWriter.java

示例12: length

import java.nio.charset.CoderResult; //导入方法依赖的package包/类
/**
 * Compute lenght of this sequence - quite expensive operation, indeed.
 */
@Override
public int length() {
    if (length != -1) {
        return length;
    }
    long start = System.currentTimeMillis();
    int charactersRead = 0;
    long bytesRead = 0;
    MappedByteBuffer mappedByteBuffer = null;
    CharBuffer charBuffer = CharBuffer.allocate(SIZE_LIMIT);
    CharsetDecoder decoder = prepareDecoder(charset);
    decoder.onUnmappableCharacter(CodingErrorAction.IGNORE);

    try {
        while (bytesRead < fileSize) {
            mappedByteBuffer = fileChannel.map(
                    FileChannel.MapMode.READ_ONLY, bytesRead,
                    Math.min(SIZE_LIMIT, fileSize - bytesRead));
            CoderResult result;
            do {
                charBuffer.clear();
                result = decoder.decode(
                        mappedByteBuffer, charBuffer,
                        bytesRead + SIZE_LIMIT >= fileSize);
                if (result.isUnmappable() || result.isMalformed()
                        || result.isError()) {
                    throw new IOException("Error decoding file: "
                            + result.toString() + " ");
                }
                if (bytesRead + SIZE_LIMIT >= fileSize) {
                    LOG.info("Coding end");
                }
                charactersRead += charBuffer.position();
            } while (result.isOverflow());

            int readNow = mappedByteBuffer.position();
            bytesRead += readNow;
            unmap(mappedByteBuffer);
        }
        charBuffer.clear();
        boolean repeat;
        do {
            repeat = decoder.flush(charBuffer).isOverflow();
            charactersRead += charBuffer.position();
            charBuffer.clear();
        } while (repeat);
    } catch (IOException ex) {
        if (mappedByteBuffer != null) {
            unmap(mappedByteBuffer);
        }
        Exceptions.printStackTrace(ex);
    }
    length = charactersRead;
    LOG.log(Level.INFO, "Length computed in {0} ms.", //NOI18N
            System.currentTimeMillis() - start);
    return length;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:61,代码来源:FastMatcher.java


注:本文中的java.nio.charset.CoderResult.toString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。