Refine search
@After public void checkRegisteredBytes() { BytesUtil.checkRegisteredBytes(); } }
@NotNull @Override public String read(@NotNull Bytes in, long size, @Nullable String using) { if (0 > size || size > Integer.MAX_VALUE) throw new IllegalStateException("positive int size expected, " + size + " given"); sb.setLength(0); BytesUtil.parseUtf8(in, sb, (int) size); return sb.toString(); }
@Override public void write(@NotNull Bytes out, long size, @NotNull CharSequence toWrite) { BytesUtil.appendUtf8(out, toWrite); }
@Override public boolean equals(Object obj) { if (!(obj instanceof Set)) return false; @NotNull Set<Entry<K, V>> set = (Set<Entry<K, V>>) obj; if (set.size() != size()) return false; for (@Nullable Entry<K, V> entry : set) { if (entry == null) return false; K key = entry.getKey(); if (key == null) return false; @Nullable V value = mapView.get(key); if (!BytesUtil.equals(entry.getValue(), value)) return false; } return true; } }
/** * 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); } } }
@NotNull public BytesTextMethodTester run() throws IOException { Bytes bytes0 = HexDumpBytes.fromText(BytesUtil.readFile(setup)); expected = BytesUtil.readFile(output).toString().trim().replace("\r", ""); Bytes text = BytesUtil.readFile(input); for (String text2 : text.toString().split("###[^\n]*\n")) { if (text2.trim().length() <= 0)
/** * Compares bytes of this {@code Data} to the given bytes {@code source}, starting from the * given offset. * <p> * <p>Default implementation compares {@link #bytes()} of this {@code Data}, but custom * implementation may only check if {@linkplain #get() object} of this {@code Data} <i>would</i> * be serialized to the same bytes sequence, if this {@code Data} wraps an object and obtaining * {@link #bytes()} requires serialization internally. * * @param source the bytes source, to compare this {@code Data}'s bytes with * @param sourceOffset the offset in the bytes source, the bytes sequence starts from * @return {@code true} if the given bytes sequence is equivalent to this {@code Data}'s bytes, * byte-by-byte */ default boolean equivalent(RandomDataInput source, long sourceOffset) { return BytesUtil.bytesEqual(source, sourceOffset, bytes(), offset(), size()); }
@Override public int storingLength(long size) { return BytesUtil.stopBitLength(size); }
private static String loadTextResource(String resourceName) throws IOException { URL titleUrl = XclDocGenerator.class.getResource(resourceName); TextWire textWire = new TextWire(BytesUtil.readFile(titleUrl.getPath())); return textWire.toString(); }
default boolean replaceIfEqual(K key, V oldValue, V newValue) { if (containsKey(key) && BytesUtil.equals(get(key), oldValue)) { put(key, newValue); return true; } else { return false; } }
default boolean readBoolean() { byte b = readByte(); return BytesUtil.byteToBoolean(b); }
@Override public long readSize(Bytes in) { return BytesUtil.readStopBit(in); }
@Override default void readMarshallable(BytesIn bytes) throws IORuntimeException { BytesUtil.readMarshallable(this, bytes); }
@NotNull @Override public StringBuilder read(Bytes in, long size, @Nullable StringBuilder using) { if (0 > size || size > Integer.MAX_VALUE) throw new IllegalStateException("positive int size expected, " + size + " given"); int csLen = (int) size; if (using == null) { using = new StringBuilder(csLen); } else { using.setLength(0); using.ensureCapacity(csLen); } BytesUtil.parseUtf8(in, using, csLen); return using; }
@Override public Data<T> getData(@NotNull T cs) { this.cs = cs; bytes.clear(); BytesUtil.appendUtf8(bytes, cs); return this; }
@Override public boolean equals(Object obj) { if (obj instanceof Map) { @NotNull Map map = (Map) obj; // todo use longSize() if (size() != map.size()) return false; try { for (int i = 0; i < kvStore.segments(); i++) { kvStore.entriesFor(i, e -> { if (!BytesUtil.equals(e.getValue(), map.get(e.getKey()))) throw new InvalidSubscriberException(); }); } return true; } catch (InvalidSubscriberException e) { return false; } } return false; }
BytesUtil.bytesEqual(s.segmentBS, currentKeyOffset, s.segmentBS, e.keyOffset, currentKeySize)) { report(corruptionListener, corruption, segmentIndex, () ->
@Override int sizeInBits() { if (maxUtf8Length == null) throw new IllegalStateException("@MaxUtf8Length must be specified for a field " + name); int sizeInBytes = BytesUtil.stopBitLength(maxUtf8Length.value()) + maxUtf8Length.value(); return sizeInBytes * 8; }
default boolean removeIfEqual(K key, V value) { if (!isKeyType(key)) return false; if (containsKey(key) && BytesUtil.equals(get(key), value)) { remove(key); return true; } else { return false; } }
/** * Read boolean at an offset * * @param offset to read * @return the boolean * @throws BufferUnderflowException if the offset is outside the limits of the Bytes */ @ForceInline default boolean readBoolean(long offset) throws BufferUnderflowException { return BytesUtil.byteToBoolean(readByte(offset)); }