本文整理匯總了Java中java.nio.charset.CoderResult.malformedForLength方法的典型用法代碼示例。如果您正苦於以下問題:Java CoderResult.malformedForLength方法的具體用法?Java CoderResult.malformedForLength怎麽用?Java CoderResult.malformedForLength使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.nio.charset.CoderResult
的用法示例。
在下文中一共展示了CoderResult.malformedForLength方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: decodeBufferLoop
import java.nio.charset.CoderResult; //導入方法依賴的package包/類
private CoderResult decodeBufferLoop(ByteBuffer src,
CharBuffer dst)
{
int mark = src.position();
try {
while (src.hasRemaining()) {
byte b = src.get();
if (b >= 0) {
if (!dst.hasRemaining())
return CoderResult.OVERFLOW;
dst.put((char)b);
mark++;
continue;
}
return CoderResult.malformedForLength(1);
}
return CoderResult.UNDERFLOW;
} finally {
src.position(mark);
}
}
示例2: parse
import java.nio.charset.CoderResult; //導入方法依賴的package包/類
/**
* Parses a UCS-4 character from the given source buffer, handling
* surrogates.
*
* @param c The first character
* @param in The source buffer, from which one more character
* will be consumed if c is a high surrogate
*
* @returns Either a parsed UCS-4 character, in which case the isPair()
* and increment() methods will return meaningful values, or
* -1, in which case error() will return a descriptive result
* object
*/
public int parse(char c, CharBuffer in) {
if (Character.isHighSurrogate(c)) {
if (!in.hasRemaining()) {
error = CoderResult.UNDERFLOW;
return -1;
}
char d = in.get();
if (Character.isLowSurrogate(d)) {
character = Character.toCodePoint(c, d);
isPair = true;
error = null;
return character;
}
error = CoderResult.malformedForLength(1);
return -1;
}
if (Character.isLowSurrogate(c)) {
error = CoderResult.malformedForLength(1);
return -1;
}
character = c;
isPair = false;
error = null;
return character;
}
示例3: lookupN
import java.nio.charset.CoderResult; //導入方法依賴的package包/類
private static CoderResult lookupN(ByteBuffer src, int n)
{
for (int i = 1; i < n; i++) {
if (isNotContinuation(src.get()))
return CoderResult.malformedForLength(i);
}
return CoderResult.malformedForLength(n);
}
示例4: malformedForLength
import java.nio.charset.CoderResult; //導入方法依賴的package包/類
private static CoderResult malformedForLength(ByteBuffer src,
int sp,
CharBuffer dst,
int dp,
int malformedNB)
{
updatePositions(src, sp, dst, dp);
return CoderResult.malformedForLength(malformedNB);
}
示例5: generate
import java.nio.charset.CoderResult; //導入方法依賴的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 da The destination array, to which one or two UTF-16
* characters will be written
* @param dp The destination position
* @param dl The destination limit
*
* @returns 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, char[] da, int dp, int dl) {
if (Character.isBmpCodePoint(uc)) {
char c = (char) uc;
if (Character.isSurrogate(c)) {
error = CoderResult.malformedForLength(len);
return -1;
}
if (dl - dp < 1) {
error = CoderResult.OVERFLOW;
return -1;
}
da[dp] = c;
error = null;
return 1;
} else if (Character.isValidCodePoint(uc)) {
if (dl - dp < 2) {
error = CoderResult.OVERFLOW;
return -1;
}
da[dp] = Character.highSurrogate(uc);
da[dp + 1] = Character.lowSurrogate(uc);
error = null;
return 2;
} else {
error = CoderResult.unmappableForLength(len);
return -1;
}
}
示例6: encodeLoop
import java.nio.charset.CoderResult; //導入方法依賴的package包/類
protected CoderResult encodeLoop(CharBuffer src, ByteBuffer dst) {
int mark = src.position();
if (!doneBOM && src.hasRemaining()) {
if (dst.remaining() < 4)
return CoderResult.OVERFLOW;
put(BOM_BIG, dst);
doneBOM = true;
}
try {
while (src.hasRemaining()) {
char c = src.get();
if (!Character.isSurrogate(c)) {
if (dst.remaining() < 4)
return CoderResult.OVERFLOW;
mark++;
put(c, dst);
} else if (Character.isHighSurrogate(c)) {
if (!src.hasRemaining())
return CoderResult.UNDERFLOW;
char low = src.get();
if (Character.isLowSurrogate(low)) {
if (dst.remaining() < 4)
return CoderResult.OVERFLOW;
mark += 2;
put(Character.toCodePoint(c, low), dst);
} else {
return CoderResult.malformedForLength(1);
}
} else {
// assert Character.isLowSurrogate(c);
return CoderResult.malformedForLength(1);
}
}
return CoderResult.UNDERFLOW;
} finally {
src.position(mark);
}
}
示例7: malformedForLength
import java.nio.charset.CoderResult; //導入方法依賴的package包/類
private static CoderResult malformedForLength(ByteBuffer src,
int mark,
int malformedNB)
{
src.position(mark);
return CoderResult.malformedForLength(malformedNB);
}
示例8: generate
import java.nio.charset.CoderResult; //導入方法依賴的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 da The destination array, to which one or two UTF-16
* characters will be written
* @param dp The destination position
* @param dl The destination limit
*
* @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, char[] da, int dp, int dl) {
if (Character.isBmpCodePoint(uc)) {
char c = (char) uc;
if (Character.isSurrogate(c)) {
error = CoderResult.malformedForLength(len);
return -1;
}
if (dl - dp < 1) {
error = CoderResult.OVERFLOW;
return -1;
}
da[dp] = c;
error = null;
return 1;
} else if (Character.isValidCodePoint(uc)) {
if (dl - dp < 2) {
error = CoderResult.OVERFLOW;
return -1;
}
da[dp] = Character.highSurrogate(uc);
da[dp + 1] = Character.lowSurrogate(uc);
error = null;
return 2;
} else {
error = CoderResult.unmappableForLength(len);
return -1;
}
}
示例9: decodeBufferLoop
import java.nio.charset.CoderResult; //導入方法依賴的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.remaining() < 3)
return CoderResult.UNDERFLOW;
byte1 = src.get() & 0xff;
inputSize = 2;
if ( byte1 == 0xa2)
mappingTableG2 = mappingTableG2a2;
else if ( byte1 == 0xac)
mappingTableG2 = mappingTableG2ac;
else if ( byte1 == 0xad)
mappingTableG2 = mappingTableG2ad;
else
return CoderResult.malformedForLength(2);
byte1 = src.get() & 0xff;
if ( byte1 < 0xa1 || byte1 > 0xfe)
return CoderResult.malformedForLength(3);
byte2 = src.get() & 0xff;
if ( byte2 < 0xa1 || byte2 > 0xfe)
return CoderResult.malformedForLength(4);
inputSize = 4;
outputChar = mappingTableG2.charAt(((byte1 - 0xa1) * 94) + byte2 - 0xa1);
} else if (byte1 == SS3 ) {
return CoderResult.malformedForLength(1);
} 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);
}
}
示例10: crMalformedOrUnderFlow
import java.nio.charset.CoderResult; //導入方法依賴的package包/類
protected CoderResult crMalformedOrUnderFlow(int b) {
if (b == SS2 || b == SS3 )
return CoderResult.malformedForLength(1);
return CoderResult.UNDERFLOW;
}
示例11: implFlush
import java.nio.charset.CoderResult; //導入方法依賴的package包/類
protected CoderResult implFlush(ByteBuffer out) {
return CoderResult.malformedForLength(1);
}
示例12: decodeNotHasArray
import java.nio.charset.CoderResult; //導入方法依賴的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);
}
}
示例13: decodeArrayLoop
import java.nio.charset.CoderResult; //導入方法依賴的package包/類
private CoderResult decodeArrayLoop(ByteBuffer src, CharBuffer dst) {
byte[] sa = src.array();
int sp = src.arrayOffset() + src.position();
int sl = src.arrayOffset() + src.limit();
assert (sp <= sl);
sp = (sp <= sl ? sp : sl);
char[] da = dst.array();
int dp = dst.arrayOffset() + dst.position();
int dl = dst.arrayOffset() + dst.limit();
assert (dp <= dl);
dp = (dp <= dl ? dp : dl);
try {
while (sp < sl) {
int b1, b2;
b1 = sa[sp];
int inputSize = 1;
int v = 0;
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 (sl - sp < 2)
return CoderResult.UNDERFLOW;
b2 = sa[sp + 1];
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 == '\uFFFD')
return CoderResult.unmappableForLength(inputSize);
if (dl - dp < 1)
return CoderResult.OVERFLOW;
da[dp++] = outputChar;
}
sp += inputSize;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(sp - src.arrayOffset());
dst.position(dp - dst.arrayOffset());
}
}
示例14: decodeBufferLoop
import java.nio.charset.CoderResult; //導入方法依賴的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);
}
}
示例15: decodeLoop
import java.nio.charset.CoderResult; //導入方法依賴的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);
}
}