本文整理匯總了Java中java.nio.CharBuffer.put方法的典型用法代碼示例。如果您正苦於以下問題:Java CharBuffer.put方法的具體用法?Java CharBuffer.put怎麽用?Java CharBuffer.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.nio.CharBuffer
的用法示例。
在下文中一共展示了CharBuffer.put方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getComputedChars
import java.nio.CharBuffer; //導入方法依賴的package包/類
/**
* Returns a UTF8 decoded <code>char[]</code> representation of the
* <code>byte[]</code> used to create this buffer.
*
* @return A char[]
*/
private char[] getComputedChars()
{
if ( computedChars == null )
{
CharBuffer charBuffer = UTF8.decode(
ByteBuffer.wrap( originalBytes, 0, originalBytes.length ) );
computedChars = new char[charBuffer.remaining()];
charBuffer.get( computedChars );
// clear out the temporary bytebuffer
charBuffer.flip();
char[] nullifier = new char[charBuffer.limit()];
Arrays.fill( nullifier, ( char ) 0 );
charBuffer.put( nullifier );
}
return computedChars;
}
示例2: decodeBufferLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) {
int mark = src.position();
try {
while (src.hasRemaining()) {
char[] cc = null;
int b1 = src.get() & 0xff;
char c = decodeSingle(b1);
int inSize = 1, outSize = 1;
if (c == UNMAPPABLE) {
if (src.remaining() < 1)
return CoderResult.UNDERFLOW;
int b2 = src.get() & 0xff;
inSize++;
c = decodeDouble(b1, b2);
if (c == UNMAPPABLE) {
cc = decodeDoubleEx(b1, b2);
if (cc == null) {
if (decodeSingle(b2) == UNMAPPABLE)
return CoderResult.unmappableForLength(2);
else
return CoderResult.unmappableForLength(1);
}
outSize++;
}
}
if (dst.remaining() < outSize)
return CoderResult.OVERFLOW;
if (outSize == 2) {
dst.put(cc[0]);
dst.put(cc[1]);
} else {
dst.put(c);
}
mark += inSize;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(mark);
}
}
示例3: generate
import java.nio.CharBuffer; //導入方法依賴的package包/類
/**
* Generates one or two UTF-16 characters to represent the given UCS-4
* character.
*
* @param uc The UCS-4 character
* @param len The number of input bytes from which the UCS-4 value
* was constructed (used when creating result objects)
* @param dst The destination buffer, to which one or two UTF-16
* characters will be written
*
* @return Either a positive count of the number of UTF-16 characters
* written to the destination buffer, or -1, in which case
* error() will return a descriptive result object
*/
public int generate(int uc, int len, CharBuffer dst) {
if (uc <= 0xffff) {
if (is(uc)) {
error = CoderResult.malformedForLength(len);
return -1;
}
if (dst.remaining() < 1) {
error = CoderResult.OVERFLOW;
return -1;
}
dst.put((char)uc);
error = null;
return 1;
}
if (uc < UCS4_MIN) {
error = CoderResult.malformedForLength(len);
return -1;
}
if (uc <= UCS4_MAX) {
if (dst.remaining() < 2) {
error = CoderResult.OVERFLOW;
return -1;
}
dst.put(high(uc));
dst.put(low(uc));
error = null;
return 2;
}
error = CoderResult.unmappableForLength(len);
return -1;
}
示例4: read
import java.nio.CharBuffer; //導入方法依賴的package包/類
@Override
public synchronized int read(CharBuffer target) throws IOException {
checkNotNull(target);
checkOpen();
if (!hasRemaining()) {
return -1;
}
int charsToRead = Math.min(target.remaining(), remaining());
for (int i = 0; i < charsToRead; i++) {
target.put(seq.charAt(pos++));
}
return charsToRead;
}
示例5: main
import java.nio.CharBuffer; //導入方法依賴的package包/類
public static void main(String[] args) {
char[] data="UsingBuffers".toCharArray();
ByteBuffer bb=ByteBuffer.allocate(data.length*2);
CharBuffer cb=bb.asCharBuffer();
cb.put(data);
print(cb.rewind());
symmetricScramble(cb);
print(cb.rewind());
symmetricScramble(cb);
print(cb.rewind());
}
示例6: decodeLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) {
while (in.hasRemaining()) {
byte b = in.get();
if (base64mode) {
if (b == unshift) {
if (base64bitsWaiting())
return malformed(in);
if (justShifted) {
if (!out.hasRemaining())
return overflow(in);
out.put((char) shift);
} else
justUnshifted = true;
setUnshifted();
} else {
if (!out.hasRemaining())
return overflow(in);
CoderResult result = handleBase64(in, out, b);
if (result != null)
return result;
}
justShifted = false;
} else {
if (b == shift) {
base64mode = true;
if (justUnshifted && strict)
return malformed(in);
justShifted = true;
continue;
}
if (!out.hasRemaining())
return overflow(in);
out.put((char) b);
justUnshifted = false;
}
}
return CoderResult.UNDERFLOW;
}
示例7: decodeBufferLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) {
int mark = src.position();
try {
while (src.hasRemaining()) {
int byte1, byte2;
int inputSize = 1;
char outputChar = '\uFFFD';
byte1 = src.get() & 0xff;
if (byte1 == SS2) {
if (!src.hasRemaining())
return CoderResult.UNDERFLOW;
byte1 = src.get() & 0xff;
inputSize = 2;
if ( byte1 < 0xa1 || byte1 > 0xfe) { //valid first byte for G2
return CoderResult.malformedForLength(2);
}
outputChar = mappingTableG2.charAt(byte1 - 0xa1);
} else if (byte1 == SS3 ) { //G3
if (src.remaining() < 2)
return CoderResult.UNDERFLOW;
byte1 = src.get() & 0xff;
if ( byte1 < 0xa1 || byte1 > 0xfe) {
return CoderResult.malformedForLength(2);
}
byte2 = src.get() & 0xff;
if ( byte2 < 0xa1 || byte2 > 0xfe) {
return CoderResult.malformedForLength(3);
}
inputSize = 3;
outputChar = mappingTableG3.charAt(((byte1 - 0xa1) * 94) + byte2 - 0xa1);
} else if ( byte1 <= 0x9f ) { // valid single byte
outputChar = byteToCharTable.charAt(byte1);
} else if (byte1 < 0xa1 || byte1 > 0xfe) { // invalid range?
return CoderResult.malformedForLength(1);
} else { // G1
if (src.remaining() < 1)
return CoderResult.UNDERFLOW;
byte2 = src.get() & 0xff;
if ( byte2 < 0xa1 || byte2 > 0xfe) {
return CoderResult.malformedForLength(2);
}
inputSize = 2;
outputChar = mappingTableG1.charAt(((byte1 - 0xa1) * 94) + byte2 - 0xa1);
}
if (outputChar == '\uFFFD')
return CoderResult.unmappableForLength(inputSize);
if (!dst.hasRemaining())
return CoderResult.OVERFLOW;
dst.put(outputChar);
mark += inputSize;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(mark);
}
}
示例8: decodeBufferLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult decodeBufferLoop(ByteBuffer src,
CharBuffer dst)
{
int mark = src.position();
int b1 = 0, b2 = 0;
int inputSize = 0;
char outputChar = REPLACE_CHAR; // U+FFFD;
try {
while (src.hasRemaining()) {
b1 = src.get() & 0xff;
inputSize = 1;
if ((b1 & 0x80) == 0) {
outputChar = (char)b1;
} else { // Multibyte char
if ((b1 & 0xff) == 0x8f) { // JIS0212
if (src.remaining() < 2)
return CoderResult.UNDERFLOW;
b1 = src.get() & 0xff;
b2 = src.get() & 0xff;
inputSize += 2;
outputChar = decode0212(b1-0x80, b2-0x80);
} else {
// JIS0208
if (src.remaining() < 1)
return CoderResult.UNDERFLOW;
b2 = src.get() & 0xff;
inputSize++;
outputChar = decodeDouble(b1, b2);
}
}
if (outputChar == REPLACE_CHAR) {
return CoderResult.unmappableForLength(inputSize);
}
if (dst.remaining() < 1)
return CoderResult.OVERFLOW;
dst.put(outputChar);
mark += inputSize;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(mark);
}
}
示例9: decodeBufferLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
protected CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) {
int mark = src.position();
try {
while (src.hasRemaining()) {
int b1 = src.get() & 0xff;
int inSize = 1;
if (b1 == SO) { // Shift out
if (currentState != SBCS)
return CoderResult.malformedForLength(1);
else
currentState = DBCS;
} else if (b1 == SI) {
if (currentState != DBCS)
return CoderResult.malformedForLength(1);
else
currentState = SBCS;
} else {
char c = UNMAPPABLE_DECODING;
if (currentState == SBCS) {
c = b2cSB[b1];
if (c == UNMAPPABLE_DECODING)
return CoderResult.unmappableForLength(1);
} else {
if (src.remaining() < 1)
return CoderResult.UNDERFLOW;
int b2 = src.get()&0xff;
if (b2 < b2Min || b2 > b2Max ||
(c = b2c[b1][b2 - b2Min]) == UNMAPPABLE_DECODING) {
if (!isDoubleByte(b1, b2))
return CoderResult.malformedForLength(2);
return CoderResult.unmappableForLength(2);
}
inSize++;
}
if (dst.remaining() < 1)
return CoderResult.OVERFLOW;
dst.put(c);
}
mark += inSize;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(mark);
}
}
示例10: decodeBufferLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) {
int mark = src.position();
try {
while (src.hasRemaining()) {
int b1, b2;
int v = 0;
b1 = src.get();
int inputSize = 1;
char outputChar = REPLACE_CHAR;
if (b1 < 0)
b1 += 256;
if (b1 == SO) { // Shift out
// For SO characters - simply validate the state and if OK
// update the state and go to the next byte
if (currentState != SBCS)
return CoderResult.malformedForLength(1);
else
currentState = DBCS;
} else if (b1 == SI) {
// For SI characters - simply validate the state and if OK
// update the state and go to the next byte
if (currentState != DBCS) {
return CoderResult.malformedForLength(1);
} else {
currentState = SBCS;
}
} else {
if (currentState == SBCS) {
outputChar = singleByteToChar.charAt(b1);
} else {
if (src.remaining() < 1)
return CoderResult.UNDERFLOW;
b2 = src.get();
if (b2 < 0)
b2 += 256;
inputSize++;
// Check validity of dbcs ebcdic byte pair values
if ((b1 != 0x40 || b2 != 0x40) &&
(b2 < 0x41 || b2 > 0xfe)) {
return CoderResult.malformedForLength(2);
}
// Lookup in the two level index
v = b1 * 256 + b2;
outputChar = index2.charAt(index1[((v & mask1) >> shift)]
+ (v & mask2));
}
if (outputChar == REPLACE_CHAR)
return CoderResult.unmappableForLength(inputSize);
if (!dst.hasRemaining())
return CoderResult.OVERFLOW;
dst.put(outputChar);
}
mark += inputSize;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(mark);
}
}
示例11: main
import java.nio.CharBuffer; //導入方法依賴的package包/類
/**
*
* @param args
*/
public static void main(String args[]) {
CharBuffer charBuffer = CharBuffer.allocate(BUF_SIZE);
File file = new File("temp.txt");
file.deleteOnExit();
charBuffer.put(str);
charBuffer.flip();
checkFileContent(charBuffer, file, str);
charBuffer.position(10);
checkFileContent(charBuffer, file, str.substring(10));
charBuffer.position(charBuffer.limit());
checkFileContent(charBuffer, file, str.substring(charBuffer.limit()));
char arr[] = new char[BUF_SIZE];
charBuffer = CharBuffer.wrap(arr);
charBuffer.put(str);
charBuffer.flip();
checkFileContent(charBuffer, file, str);
charBuffer.position(10);
checkFileContent(charBuffer, file, str.substring(10));
charBuffer.position(charBuffer.limit());
checkFileContent(charBuffer, file, str.substring(charBuffer.limit()));
char secArr[] = new char[BUF_SIZE];
charBuffer = CharBuffer.wrap(secArr);
charBuffer.put(str);
charBuffer.position(5);
charBuffer.limit(str.length() - 7);
charBuffer = charBuffer.slice();
checkFileContent(charBuffer, file, str.substring(5, (str.length() - 7)));
charBuffer.position(10);
checkFileContent(charBuffer, file, str.substring(15, (str.length() - 7)));
charBuffer.position(charBuffer.limit());
checkFileContent(charBuffer, file, str.substring(charBuffer.limit()));
charBuffer = ByteBuffer.allocate(BUF_SIZE).asCharBuffer();
charBuffer.put(str);
charBuffer.flip();
checkFileContent(charBuffer, file, str);
charBuffer.position(10);
checkFileContent(charBuffer, file, str.substring(10));
charBuffer.position(charBuffer.limit());
checkFileContent(charBuffer, file, str.substring(charBuffer.limit()));
charBuffer = ByteBuffer.allocateDirect(1024).asCharBuffer();
charBuffer.put(str);
charBuffer.flip();
checkFileContent(charBuffer, file, str);
charBuffer.position(10);
checkFileContent(charBuffer, file, str.substring(10));
charBuffer.position(charBuffer.limit());
checkFileContent(charBuffer, file, str.substring(charBuffer.limit()));
}
示例12: decodeBufferLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
protected CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) {
int mark = src.position();
try {
while (src.hasRemaining()) {
char[] cc = null;
int b1 = src.get() & 0xff;
int inSize = 1, outSize = 1;
char c = decodeSingle(b1);
if (c == UNMAPPABLE_DECODING) {
if (src.remaining() < 1)
return CoderResult.UNDERFLOW;
int b2 = src.get() & 0xff;
inSize++;
if (b2 < b2Min || b2 > b2Max)
return CoderResult.unmappableForLength(2);
c = decodeDouble(b1, b2); //bmp
if (c == UNMAPPABLE_DECODING) {
c = decodeDoubleEx(b1, b2); //supp
if (c == UNMAPPABLE_DECODING) {
c = decodeBig5(b1, b2); //big5
if (c == UNMAPPABLE_DECODING)
return CoderResult.unmappableForLength(2);
} else {
outSize = 2;
}
}
}
if (dst.remaining() < outSize)
return CoderResult.OVERFLOW;
if (outSize == 2) {
dst.put(Surrogate.high(0x20000 + c));
dst.put(Surrogate.low(0x20000 + c));
} else {
dst.put(c);
}
mark += inSize;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(mark);
}
}
示例13: decodeBufferLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult decodeBufferLoop(ByteBuffer src,
CharBuffer dst)
{
int mark = src.position();
try {
while (src.hasRemaining()) {
char outputChar;
byte byte1 = src.get();
byte byte2 = 0;
if ((byte1 & MSB) == 0) { // ASCII G0
if (!dst.hasRemaining())
return CoderResult.OVERFLOW;
dst.put((char) byte1);
mark++;
} else if (byte1 == SS2) { // Codeset 2 G2
if ( src.remaining() < 3)
return CoderResult.UNDERFLOW;
int cnsPlane = (src.get() & 0xff) - 0xa0;
// Adjust String array index for plane 15
cnsPlane = (cnsPlane == 15)? 8 : cnsPlane;
if (cnsPlane - 2 >= cnsChars.length || cnsPlane - 2 < 0)
return CoderResult.malformedForLength(2);
byte1 = src.get();
byte2 = src.get();
if (!isLegalDB(byte1) || !isLegalDB(byte2))
return CoderResult.malformedForLength(4);
if (cnsPlane < 3) {
outputChar = convToUnicode(byte1, byte2,
cnsChars[cnsPlane - 2]);
if (outputChar == REPLACE_CHAR)
return CoderResult.unmappableForLength(4);
if (!dst.hasRemaining())
return CoderResult.OVERFLOW;
dst.put(outputChar);
} else {
char[] outSurr = convToSurrogate(byte1, byte2,
cnsChars[cnsPlane - 2]);
if (outSurr == null)
return CoderResult.malformedForLength(4);
if (outSurr[0] == '\u0000') {
if (!dst.hasRemaining())
return CoderResult.OVERFLOW;
if (outSurr[1] == REPLACE_CHAR)
return CoderResult.unmappableForLength(4);
dst.put(outSurr[1]);
} else {
if (dst.remaining() < 2)
return CoderResult.OVERFLOW;
dst.put(outSurr[0]);
dst.put(outSurr[1]);
}
}
mark += 4;
} else { // Codeset 1 G1
if (!src.hasRemaining())
return CoderResult.UNDERFLOW;
byte2 = src.get();
if (!isLegalDB(byte1) || !isLegalDB(byte2))
return CoderResult.malformedForLength(1);
outputChar = convToUnicode(byte1,
byte2,
unicodeCNS1);
if (outputChar == REPLACE_CHAR)
return CoderResult.unmappableForLength(2);
if (!dst.hasRemaining())
return CoderResult.OVERFLOW;
dst.put(outputChar);
mark +=2;
}
}
return CoderResult.UNDERFLOW;
} finally {
src.position(mark);
}
}
示例14: decodeLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
protected CoderResult decodeLoop(ByteBuffer src, CharBuffer dst) {
if (src.remaining() < 4)
return CoderResult.UNDERFLOW;
int mark = src.position();
int cp;
try {
if (currentBO == NONE) {
cp = ((src.get() & 0xff) << 24) |
((src.get() & 0xff) << 16) |
((src.get() & 0xff) << 8) |
(src.get() & 0xff);
if (cp == BOM_BIG && expectedBO != LITTLE) {
currentBO = BIG;
mark += 4;
} else if (cp == BOM_LITTLE && expectedBO != BIG) {
currentBO = LITTLE;
mark += 4;
} else {
if (expectedBO == NONE)
currentBO = BIG;
else
currentBO = expectedBO;
src.position(mark);
}
}
while (src.remaining() >= 4) {
cp = getCP(src);
if (Character.isBmpCodePoint(cp)) {
if (!dst.hasRemaining())
return CoderResult.OVERFLOW;
mark += 4;
dst.put((char) cp);
} else if (Character.isValidCodePoint(cp)) {
if (dst.remaining() < 2)
return CoderResult.OVERFLOW;
mark += 4;
dst.put(Character.highSurrogate(cp));
dst.put(Character.lowSurrogate(cp));
} else {
return CoderResult.malformedForLength(4);
}
}
return CoderResult.UNDERFLOW;
} finally {
src.position(mark);
}
}
示例15: decodeNotHasArray
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult decodeNotHasArray(ByteBuffer in, CharBuffer out) {
int outRemaining = out.remaining();
int pos = in.position();
int limit = in.limit();
try {
while (pos < limit) {
if (outRemaining == 0) {
return CoderResult.OVERFLOW;
}
int jchar = in.get();
if (jchar < 0) {
jchar = jchar & 0x7F;
int tail = remainingBytes[jchar];
if (tail == -1) {
return CoderResult.malformedForLength(1);
}
if (limit - pos < 1 + tail) {
// No early test for invalid sequences here as peeking
// at the next byte is harder
return CoderResult.UNDERFLOW;
}
int nextByte;
for (int i = 0; i < tail; i++) {
nextByte = in.get() & 0xFF;
if ((nextByte & 0xC0) != 0x80) {
return CoderResult.malformedForLength(1 + i);
}
jchar = (jchar << 6) + nextByte;
}
jchar -= remainingNumbers[tail];
if (jchar < lowerEncodingLimit[tail]) {
// Should have been encoded in a fewer octets
return CoderResult.malformedForLength(1);
}
pos += tail;
}
// Apache Tomcat added test
if (jchar >= 0xD800 && jchar <= 0xDFFF) {
return CoderResult.unmappableForLength(3);
}
// Apache Tomcat added test
if (jchar > 0x10FFFF) {
return CoderResult.unmappableForLength(4);
}
if (jchar <= 0xffff) {
out.put((char) jchar);
outRemaining--;
} else {
if (outRemaining < 2) {
return CoderResult.OVERFLOW;
}
out.put((char) ((jchar >> 0xA) + 0xD7C0));
out.put((char) ((jchar & 0x3FF) + 0xDC00));
outRemaining -= 2;
}
pos++;
}
return CoderResult.UNDERFLOW;
} finally {
in.position(pos);
}
}