本文整理匯總了Java中java.nio.CharBuffer.get方法的典型用法代碼示例。如果您正苦於以下問題:Java CharBuffer.get方法的具體用法?Java CharBuffer.get怎麽用?Java CharBuffer.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.nio.CharBuffer
的用法示例。
在下文中一共展示了CharBuffer.get方法的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: encodeBufferLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult encodeBufferLoop(CharBuffer src, ByteBuffer dst) {
int mark = src.position();
try {
while (src.hasRemaining()) {
char c = src.get();
int b = encode(c);
if (b == UNMAPPABLE_ENCODING) {
if (Character.isSurrogate(c)) {
if (sgp == null)
sgp = new Surrogate.Parser();
if (sgp.parse(c, src) < 0)
return sgp.error();
return sgp.unmappableResult();
}
return CoderResult.unmappableForLength(1);
}
if (!dst.hasRemaining())
return CoderResult.OVERFLOW;
dst.put((byte)b);
mark++;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(mark);
}
}
示例3: getTable16KeyOffsets
import java.nio.CharBuffer; //導入方法依賴的package包/類
private char[] getTable16KeyOffsets(int offset) {
int length = b16BitUnits.charAt(offset++);
if(length > 0) {
char[] result = new char[length];
if(length <= 16) {
for(int i = 0; i < length; ++i) {
result[i] = b16BitUnits.charAt(offset++);
}
} else {
CharBuffer temp = b16BitUnits.duplicate();
temp.position(offset);
temp.get(result);
}
return result;
} else {
return emptyChars;
}
}
示例4: CMapFormat2
import java.nio.CharBuffer; //導入方法依賴的package包/類
CMapFormat2(ByteBuffer buffer, int offset, char[] xlat) {
this.xlat = xlat;
int tableLen = buffer.getChar(offset+2);
buffer.position(offset+6);
CharBuffer cBuffer = buffer.asCharBuffer();
char maxSubHeader = 0;
for (int i=0;i<256;i++) {
subHeaderKey[i] = cBuffer.get();
if (subHeaderKey[i] > maxSubHeader) {
maxSubHeader = subHeaderKey[i];
}
}
/* The value of the subHeaderKey is 8 * the subHeader index,
* so the number of subHeaders can be obtained by dividing
* this value bv 8 and adding 1.
*/
int numSubHeaders = (maxSubHeader >> 3) +1;
firstCodeArray = new char[numSubHeaders];
entryCountArray = new char[numSubHeaders];
idDeltaArray = new short[numSubHeaders];
idRangeOffSetArray = new char[numSubHeaders];
for (int i=0; i<numSubHeaders; i++) {
firstCodeArray[i] = cBuffer.get();
entryCountArray[i] = cBuffer.get();
idDeltaArray[i] = (short)cBuffer.get();
idRangeOffSetArray[i] = cBuffer.get();
// System.out.println("sh["+i+"]:fc="+(int)firstCodeArray[i]+
// " ec="+(int)entryCountArray[i]+
// " delta="+(int)idDeltaArray[i]+
// " offset="+(int)idRangeOffSetArray[i]);
}
int glyphIndexArrSize = (tableLen-518-numSubHeaders*8)/2;
glyphIndexArray = new char[glyphIndexArrSize];
for (int i=0; i<glyphIndexArrSize;i++) {
glyphIndexArray[i] = cBuffer.get();
}
}
示例5: looksLikeJapanese
import java.nio.CharBuffer; //導入方法依賴的package包/類
private static boolean looksLikeJapanese(CharBuffer cb) {
int hiragana = 0; // Fullwidth Hiragana
int katakana = 0; // Halfwidth Katakana
while (cb.hasRemaining()) {
char c = cb.get();
if (0x3040 <= c && c <= 0x309f && ++hiragana > 1) return true;
if (0xff65 <= c && c <= 0xff9f && ++katakana > 1) return true;
}
return false;
}
示例6: urlDecode
import java.nio.CharBuffer; //導入方法依賴的package包/類
/**
* Decode/unescape a portion of a URL, to use with the query part ensure {@code plusAsBlank} is true.
*
* @param content the portion to decode
* @param charset the charset to use
* @param plusAsBlank if {@code true}, then convert '+' to space (e.g. for www-url-form-encoded content), otherwise leave as is.
* @return encoded string
*/
private static String urlDecode(
final String content,
final Charset charset,
final boolean plusAsBlank) {
if (content == null) {
return null;
}
final ByteBuffer bb = ByteBuffer.allocate(content.length());
final CharBuffer cb = CharBuffer.wrap(content);
while (cb.hasRemaining()) {
final char c = cb.get();
if (c == '%' && cb.remaining() >= 2) {
final char uc = cb.get();
final char lc = cb.get();
final int u = Character.digit(uc, 16);
final int l = Character.digit(lc, 16);
if (u != -1 && l != -1) {
bb.put((byte) ((u << 4) + l));
} else {
bb.put((byte) '%');
bb.put((byte) uc);
bb.put((byte) lc);
}
} else if (plusAsBlank && c == '+') {
bb.put((byte) ' ');
} else {
bb.put((byte) c);
}
}
bb.flip();
return charset.decode(bb).toString();
}
示例7: encodeBufferLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult encodeBufferLoop(CharBuffer src, ByteBuffer dst) {
int mark = src.position();
try {
while (src.hasRemaining()) {
char c = src.get();
if (Character.isSurrogate(c)) {
int surr;
if ((surr = sgp.parse(c, src)) < 0)
return sgp.error();
char c2 = Surrogate.low(surr);
byte[] outputBytes = new byte[2];
outputBytes = encodeSurrogate(c, c2);
if (outputBytes == null) {
return sgp.unmappableResult();
} else {
if (dst.remaining() < 2)
return CoderResult.OVERFLOW;
mark += 2;
dst.put(outputBytes[0]);
dst.put(outputBytes[1]);
continue;
}
}
if (c >= '\uFFFE')
return CoderResult.unmappableForLength(1);
int b = encodeSingle(c);
if (b != -1) { // Single-byte character
if (dst.remaining() < 1)
return CoderResult.OVERFLOW;
mark++;
dst.put((byte)b);
continue;
}
// Double Byte character
int ncode = encodeDouble(c);
if (ncode != 0 && c != '\u0000') {
if (dst.remaining() < 2)
return CoderResult.OVERFLOW;
mark++;
dst.put((byte) ((ncode & 0xff00) >> 8));
dst.put((byte) ncode);
continue;
}
return CoderResult.unmappableForLength(1);
}
return CoderResult.UNDERFLOW;
} finally {
src.position(mark);
}
}
示例8: process
import java.nio.CharBuffer; //導入方法依賴的package包/類
public String process(int lineNumber, String result) {
while (result.contains("\\S\\")) {
int index = result.indexOf("\\S\\");
char x = result.charAt(index + 3);
ByteBuffer b = ByteBuffer.wrap(new byte[] { (byte) (x + 128) });
CharBuffer decode = Charsets.ISO_8859_1.decode(b);
result = result.substring(0, index) + decode.get() + result.substring(index + 4);
}
return result;
}
示例9: CMapFormat10
import java.nio.CharBuffer; //導入方法依賴的package包/類
CMapFormat10(ByteBuffer bbuffer, int offset, char[] xlat) {
firstCode = bbuffer.getInt() & INTMASK;
entryCount = bbuffer.getInt() & INTMASK;
bbuffer.position(offset+20);
CharBuffer buffer = bbuffer.asCharBuffer();
glyphIdArray = new char[entryCount];
for (int i=0; i< entryCount; i++) {
glyphIdArray[i] = buffer.get();
}
}
示例10: urldecode
import java.nio.CharBuffer; //導入方法依賴的package包/類
/**
* Decode/unescape a portion of a URL, to use with the query part ensure {@code plusAsBlank} is true.
*
* @param content the portion to decode
* @param charset the charset to use
* @param plusAsBlank if {@code true}, then convert '+' to space (e.g. for www-url-form-encoded content), otherwise leave as is.
* @return encoded string
*/
private static String urldecode(
final String content,
final Charset charset,
final boolean plusAsBlank) {
if (content == null) {
return null;
}
ByteBuffer bb = ByteBuffer.allocate(content.length());
CharBuffer cb = CharBuffer.wrap(content);
while (cb.hasRemaining()) {
char c = cb.get();
if (c == '%' && cb.remaining() >= 2) {
char uc = cb.get();
char lc = cb.get();
int u = Character.digit(uc, 16);
int l = Character.digit(lc, 16);
if (u != -1 && l != -1) {
bb.put((byte) ((u << 4) + l));
} else {
bb.put((byte) '%');
bb.put((byte) uc);
bb.put((byte) lc);
}
} else if (plusAsBlank && c == '+') {
bb.put((byte) ' ');
} else {
bb.put((byte) c);
}
}
bb.flip();
return charset.decode(bb).toString();
}
示例11: urldecode
import java.nio.CharBuffer; //導入方法依賴的package包/類
/**
* Decode/unescape a portion of a URL, to use with the query part ensure {@code plusAsBlank} is true.
*
* @param content the portion to decode
* @param charset the charset to use
* @param plusAsBlank if {@code true}, then convert '+' to space (e.g. for www-url-form-encoded content), otherwise leave as is.
* @return
*/
private static String urldecode(
final String content,
final Charset charset,
final boolean plusAsBlank) {
if (content == null) {
return null;
}
ByteBuffer bb = ByteBuffer.allocate(content.length());
CharBuffer cb = CharBuffer.wrap(content);
while (cb.hasRemaining()) {
char c = cb.get();
if (c == '%' && cb.remaining() >= 2) {
char uc = cb.get();
char lc = cb.get();
int u = Character.digit(uc, 16);
int l = Character.digit(lc, 16);
if (u != -1 && l != -1) {
bb.put((byte) ((u << 4) + l));
} else {
bb.put((byte) '%');
bb.put((byte) uc);
bb.put((byte) lc);
}
} else if (plusAsBlank && c == '+') {
bb.put((byte) ' ');
} else {
bb.put((byte) c);
}
}
bb.flip();
return charset.decode(bb).toString();
}
示例12: encodeBufferLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult encodeBufferLoop(CharBuffer src, ByteBuffer dst) {
int index;
int spaceNeeded;
int i;
int mark = src.position();
try {
while (src.hasRemaining()) {
char inputChar = src.get();
boolean allZeroes = true;
if (Character.isSurrogate(inputChar)) {
if (sgp.parse(inputChar, src) < 0)
return sgp.error();
return sgp.unmappableResult();
}
if (inputChar >= '\uFFFE')
return CoderResult.unmappableForLength(1);
String theChars;
char aChar;
// We have a valid character, get the bytes for it
index = index1[((inputChar & mask1) >> shift)] + (inputChar & mask2);
if (index < 7500)
theChars = index2;
else if (index < 15000) {
index = index - 7500;
theChars = index2a;
} else if (index < 22500){
index = index - 15000;
theChars = index2b;
}
else {
index = index - 22500;
theChars = index2c;
}
aChar = theChars.charAt(2*index);
outputByte[0] = (byte)((aChar & 0xff00)>>8);
outputByte[1] = (byte)(aChar & 0x00ff);
aChar = theChars.charAt(2*index + 1);
outputByte[2] = (byte)((aChar & 0xff00)>>8);
outputByte[3] = (byte)(aChar & 0x00ff);
for (i = 0; i < outputByte.length; i++) {
if (outputByte[i] != 0x00) {
allZeroes = false;
break;
}
}
if (allZeroes && inputChar != '\u0000') {
return CoderResult.unmappableForLength(1);
}
int oindex = 0;
for (spaceNeeded = outputByte.length;
spaceNeeded > 1; spaceNeeded--){
if (outputByte[oindex++] != 0x00 )
break;
}
if (dst.remaining() < spaceNeeded)
return CoderResult.OVERFLOW;
for (i = outputByte.length - spaceNeeded;
i < outputByte.length; i++) {
dst.put(outputByte[i]);
}
mark++;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(mark);
}
}
示例13: encodeBufferLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
protected CoderResult encodeBufferLoop(CharBuffer src, ByteBuffer dst) {
int mark = src.position();
try {
while (src.hasRemaining()) {
char c = src.get();
int bb = encodeChar(c);
if (bb == UNMAPPABLE_ENCODING) {
if (Character.isSurrogate(c)) {
if (sgp().parse(c, src) < 0)
return sgp.error();
return sgp.unmappableResult();
}
return CoderResult.unmappableForLength(1);
}
if (bb > MAX_SINGLEBYTE) { // DoubleByte
if (currentState == SBCS) {
if (dst.remaining() < 1)
return CoderResult.OVERFLOW;
currentState = DBCS;
dst.put(SO);
}
if (dst.remaining() < 2)
return CoderResult.OVERFLOW;
dst.put((byte)(bb >> 8));
dst.put((byte)(bb));
} else { // Single-byte
if (currentState == DBCS) {
if (dst.remaining() < 1)
return CoderResult.OVERFLOW;
currentState = SBCS;
dst.put(SI);
}
if (dst.remaining() < 1)
return CoderResult.OVERFLOW;
dst.put((byte)bb);
}
mark++;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(mark);
}
}
示例14: encodeBufferLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult encodeBufferLoop(CharBuffer src,
ByteBuffer dst)
{
int mark = src.position();
while (src.hasRemaining()) {
char c = src.get();
if (c < 0x80) {
// Have at most seven bits
if (!dst.hasRemaining())
return overflow(src, mark);
dst.put((byte)c);
} else if (c < 0x800) {
// 2 bytes, 11 bits
if (dst.remaining() < 2)
return overflow(src, mark);
dst.put((byte)(0xc0 | (c >> 6)));
dst.put((byte)(0x80 | (c & 0x3f)));
} else if (Character.isSurrogate(c)) {
// Have a surrogate pair
if (sgp == null)
sgp = new Surrogate.Parser();
int uc = sgp.parse(c, src);
if (uc < 0) {
src.position(mark);
return sgp.error();
}
if (dst.remaining() < 4)
return overflow(src, mark);
dst.put((byte)(0xf0 | ((uc >> 18))));
dst.put((byte)(0x80 | ((uc >> 12) & 0x3f)));
dst.put((byte)(0x80 | ((uc >> 6) & 0x3f)));
dst.put((byte)(0x80 | (uc & 0x3f)));
mark++; // 2 chars
} else {
// 3 bytes, 16 bits
if (dst.remaining() < 3)
return overflow(src, mark);
dst.put((byte)(0xe0 | ((c >> 12))));
dst.put((byte)(0x80 | ((c >> 6) & 0x3f)));
dst.put((byte)(0x80 | (c & 0x3f)));
}
mark++;
}
src.position(mark);
return CoderResult.UNDERFLOW;
}
示例15: encodeBufferLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult encodeBufferLoop(CharBuffer src,
ByteBuffer dst)
{
int outputSize = 0;
byte[] outputByte;
int inputSize = 0; // Size of input
byte[] tmpBuf = new byte[3];
int mark = src.position();
try {
while (src.hasRemaining()) {
outputByte = tmpBuf;
char c = src.get();
if (Character.isSurrogate(c)) {
if (sgp.parse(c, src) < 0)
return sgp.error();
return sgp.unmappableResult();
}
outputSize = encodeSingle(c, outputByte);
if (outputSize == 0) { // DoubleByte
int ncode = encodeDouble(c);
if (ncode != 0 ) {
if ((ncode & 0xFF0000) == 0) {
outputByte[0] = (byte) ((ncode & 0xff00) >> 8);
outputByte[1] = (byte) (ncode & 0xff);
outputSize = 2;
} else {
outputByte[0] = (byte) 0x8f;
outputByte[1] = (byte) ((ncode & 0xff00) >> 8);
outputByte[2] = (byte) (ncode & 0xff);
outputSize = 3;
}
} else {
return CoderResult.unmappableForLength(1);
}
}
if (dst.remaining() < outputSize)
return CoderResult.OVERFLOW;
// Put the byte in the output buffer
for (int i = 0; i < outputSize; i++) {
dst.put(outputByte[i]);
}
mark++;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(mark);
}
}