java.nio.ByteBuffer를 통해 UTF8 문자열을 읽으려고합니다. 크기는 unsinged int이며, 물론 Java에는 없습니다. 나는 그 가치를 오래도록 가치를 읽었습니다.길이가 부호없는 int 인 ByteBuffer에서 UTF-8 문자열 읽기
내가 가지고있는 다음 문제는 long 배열을 만들 수 없다는 것이며, long으로 int 형으로 다시 캐스팅하면 서명 될 것입니다.
또한 limit() 버퍼를 사용하여 시도했지만 다시 int int 함께 작동합니다.
내가하고있는 특정 일은 클래스 파일에서 UTF8 문자열을 읽는 것이므로 버퍼에 UTF8 문자열이 더 많이 포함되어 있습니다.
ByteBuffer에서 잠재적 인 부호없는 int 길이를 가진 UTF8 문자열을 읽는 방법에 대한 아이디어.
편집 :
Here is an example of the issue.
SourceDebugExtension_attribute {
u2 attribute_name_index;
u4 attribute_length;
u1 debug_extension[attribute_length];
}
attribute_name_index
The value of the attribute_name_index item must be a valid index into the constant_pool table. The constant_pool entry at that index must be a CONSTANT_Utf8_info structure representing the string "SourceDebugExtension".
attribute_length
The value of the attribute_length item indicates the length of the attribute, excluding the initial six bytes. The value of the attribute_length item is thus the number of bytes in the debug_extension[] item.
debug_extension[]
The debug_extension array holds a string, which must be in UTF-8 format. There is no terminating zero byte.
The string in the debug_extension item will be interpreted as extended debugging information. The content of this string has no semantic effect on the Java Virtual Machine.
그래서, 기술적 인 관점에서, 길이 (4 바이트 부호) 전체 U4 인 클래스 파일에 문자열을 가질 수 있습니다.
UTF8 문자열의 크기에 제한이 있다면 문제가되지 않습니다 (저는 UTF8 전문가가 아니기 때문에 그러한 제한이있을 수 있습니다).
난 그냥에 리면 그 긴 문자열이있을 것되지 않는 현실에 갈 수 ...
인코딩이 1 바이트/문자보다 큰 경우는, 확실히 바이트 배열이 길어질 가능성이 있습니다. String는 byte [] 배열이 아니라 char [] 배열을 캡슐화합니다. –
확신 할 수 있습니다. 그래도 2GB를 치지는 못할 것입니다. – Alnitak
내 편집을 참조하십시오 ... 크기가 전혀 내 통제하에 있지 않습니다 ... – TofuBeer