A DESCRIPTION OF THE REQUEST :
Class java.nio.CharsetDecoder is often used to encode native zero-terminated ASCII strings.
If used ByteBuffer wraps from a fixed sized byte array there are probably trailing 0x00's and neither position nor limit are correctly aligned to these. Then the ByteBuffer's limit must first be aligned to the first 0x00 to avoid invalid chars in the destination CharBuffer.
For this I suggest to add following methods:
public int terminator() {
throw new UnsupportedOperationException();
}
public CharsetDecoder terminateBy(int newTerminator) {
throw new UnsupportedOperationException();
}
By default they should throw UnsupportedOperationException and should be overridden by appropriated sub classes.
JUSTIFICATION :
- zero-terminated ASCII strings are often used to access native APIs.
- is more elegant than extra lines of code
- will enhance performance, as source bytes must not be looped twice
- e.g. helps to fix bug 6449421
---------- BEGIN SOURCE ----------
Usage (e.g.):
(Possible fix for http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6449421)
return Charset.forName(charSet).newDecoder()
.onMalformedInput(CodingErrorAction.REPLACE)
.onUnmappableCharacter(CodingErrorAction.REPLACE)
.replaceWith("?")
.terminateBy(0)
.decode (ByteBuffer.wrap(inBytes))
.toString();
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
int len = 0;
while (inBytes[len] != 0)
len++;
return Charset.forName(charSet).newDecoder()
.onMalformedInput(CodingErrorAction.REPLACE)
.onUnmappableCharacter(CodingErrorAction.REPLACE)
.replaceWith("?")
.decode (ByteBuffer.wrap(inBytes, 0, len))
.toString();
Class java.nio.CharsetDecoder is often used to encode native zero-terminated ASCII strings.
If used ByteBuffer wraps from a fixed sized byte array there are probably trailing 0x00's and neither position nor limit are correctly aligned to these. Then the ByteBuffer's limit must first be aligned to the first 0x00 to avoid invalid chars in the destination CharBuffer.
For this I suggest to add following methods:
public int terminator() {
throw new UnsupportedOperationException();
}
public CharsetDecoder terminateBy(int newTerminator) {
throw new UnsupportedOperationException();
}
By default they should throw UnsupportedOperationException and should be overridden by appropriated sub classes.
JUSTIFICATION :
- zero-terminated ASCII strings are often used to access native APIs.
- is more elegant than extra lines of code
- will enhance performance, as source bytes must not be looped twice
- e.g. helps to fix bug 6449421
---------- BEGIN SOURCE ----------
Usage (e.g.):
(Possible fix for http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6449421)
return Charset.forName(charSet).newDecoder()
.onMalformedInput(CodingErrorAction.REPLACE)
.onUnmappableCharacter(CodingErrorAction.REPLACE)
.replaceWith("?")
.terminateBy(0)
.decode (ByteBuffer.wrap(inBytes))
.toString();
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
int len = 0;
while (inBytes[len] != 0)
len++;
return Charset.forName(charSet).newDecoder()
.onMalformedInput(CodingErrorAction.REPLACE)
.onUnmappableCharacter(CodingErrorAction.REPLACE)
.replaceWith("?")
.decode (ByteBuffer.wrap(inBytes, 0, len))
.toString();
- blocks
-
JDK-8158748 Speedup creation of nio.zipfs.ZipPath + performance regression from JDK-8061777
-
- Open
-