private String toString2(@NotNull NativeBytesStore bytesStore) { int length = (int) Math.min(Integer.MAX_VALUE, readRemaining()); @NotNull char[] chars = new char[length]; @Nullable final Memory memory = bytesStore.memory; final long address = bytesStore.address + bytesStore.translate(readPosition()); for (int i = 0; i < length; i++) chars[i] = (char) (memory.readByte(address + i) & 0xFF); return StringUtils.newString(chars); }
@NotNull protected String toString0() { int length = (int) Math.min(Integer.MAX_VALUE, readRemaining()); @NotNull char[] chars = new char[length]; try { for (int i = 0; i < length; i++) { chars[i] = (char) (bytesStore.readByte(readPosition() + i) & 0xFF); } } catch (BufferUnderflowException e) { // ignored } return StringUtils.newString(chars); }
public static String to8bitString(@org.jetbrains.annotations.NotNull @NotNull BytesStore bytes) throws IllegalArgumentException { long pos = bytes.readPosition(); int len = Maths.toInt32(bytes.readRemaining()); @org.jetbrains.annotations.NotNull char[] chars = new char[len]; if (bytes instanceof VanillaBytes) { ((VanillaBytes) bytes).read8Bit(chars, len); } else { for (int i = 0; i < len; i++) try { chars[i] = (char) bytes.readUnsignedByte(pos + i); } catch (Exception e) { return new String(chars, 0, len) + ' ' + e; } } return StringUtils.newString(chars); }
/** * converts the bytes to a ISO-8859-1 String, the end of the string is either the bytes .limit * () or a byte containing the stopByte ( which ever comes first ). If the string can be * obtained from the pool, this string is used instead. otherwise, the string is added to the * pool. * * @param bytes the bytes to convert to a string * @param length parse the string up to the length * @return the string made from bytes only ( rather than chars ) */ public String intern(@NotNull final Bytes bytes, int length) { try { int hash32 = BytesStoreHash.hash32(bytes, length); int h = hash32 & mask; String s = interner[h]; long position = bytes.readPosition(); if (BytesUtil.bytesEqual(s, bytes, position, length)) return s; int h2 = (hash32 >> shift) & mask; String s2 = interner[h2]; if (BytesUtil.bytesEqual(s2, bytes, position, length)) return s2; char[] chars = toCharArray(bytes, position, length); return interner[s == null || (s2 != null && toggle()) ? h : h2] = StringUtils.newString(chars); } finally { bytes.readSkip(length); } } }