Refine search
/** Returns a new CharBuffer identical to buf, except twice the capacity. */ private static CharBuffer grow(CharBuffer buf) { char[] copy = Arrays.copyOf(buf.array(), buf.capacity() * 2); CharBuffer bigger = CharBuffer.wrap(copy); bigger.position(buf.position()); bigger.limit(buf.limit()); return bigger; }
static char[] toChars(byte[] bytes) { Charset charset=Charset.forName("UTF-8"); ByteBuffer byteBuffer=ByteBuffer.wrap(bytes); CharBuffer charBuffer=charset.decode(byteBuffer); char[] chars=Arrays.copyOf(charBuffer.array(), charBuffer.limit()); Arrays.fill(charBuffer.array(), '\u0000'); // clear the cleartext Arrays.fill(byteBuffer.array(), (byte) 0); // clear the ciphertext return chars; } }
/** * Creates a new big-endian buffer whose content is a subregion of * the specified {@code string} encoded in the specified {@code charset}. * The new buffer's {@code readerIndex} and {@code writerIndex} are * {@code 0} and the length of the encoded string respectively. */ public static ByteBuf copiedBuffer( CharSequence string, int offset, int length, Charset charset) { if (string == null) { throw new NullPointerException("string"); } if (length == 0) { return EMPTY_BUFFER; } if (string instanceof CharBuffer) { CharBuffer buf = (CharBuffer) string; if (buf.hasArray()) { return copiedBuffer( buf.array(), buf.arrayOffset() + buf.position() + offset, length, charset); } buf = buf.slice(); buf.limit(length); buf.position(offset); return copiedBuffer(buf, charset); } return copiedBuffer(CharBuffer.wrap(string, offset, offset + length), charset); }
/** Returns a new CharBuffer identical to buf, except twice the capacity. */ private static CharBuffer grow(CharBuffer buf) { char[] copy = Arrays.copyOf(buf.array(), buf.capacity() * 2); CharBuffer bigger = CharBuffer.wrap(copy); bigger.position(buf.position()); bigger.limit(buf.limit()); return bigger; }
private int getArray(CharBuffer out) { if (out.hasArray()) { output = out.array(); outEnd = out.arrayOffset() + out.limit(); return out.arrayOffset() + out.position(); } else { outEnd = out.remaining(); if (allocatedOutput == null || outEnd > allocatedOutput.length) { allocatedOutput = new char[outEnd]; } // The array's start position is 0. output = allocatedOutput; return 0; } }
public void put(int index, String s) { int len = s.length(); int sLen = buffer.limit(); if (index < 0) return; char ch = len == 0 ? '\0' : s.charAt(0); if (index < sLen) buffer.put(index, ch); else { int cnt = index - sLen; CharBuffer tmp = CharBuffer.allocate(sLen + cnt + 1); tmp.put(buffer.array()); buffer = tmp; for(int i = 0; i < cnt; i++) { buffer.append('\32'); } buffer.append(ch); } }
/** Returns a new CharBuffer identical to buf, except twice the capacity. */ private static CharBuffer grow(CharBuffer buf) { char[] copy = Arrays.copyOf(buf.array(), buf.capacity() * 2); CharBuffer bigger = CharBuffer.wrap(copy); bigger.position(buf.position()); bigger.limit(buf.limit()); return bigger; }
/** * Creates a new big-endian buffer whose content is a subregion of * the specified {@code string} encoded in the specified {@code charset}. * The new buffer's {@code readerIndex} and {@code writerIndex} are * {@code 0} and the length of the encoded string respectively. */ public static ByteBuf copiedBuffer( CharSequence string, int offset, int length, Charset charset) { if (string == null) { throw new NullPointerException("string"); } if (length == 0) { return EMPTY_BUFFER; } if (string instanceof CharBuffer) { CharBuffer buf = (CharBuffer) string; if (buf.hasArray()) { return copiedBuffer( buf.array(), buf.arrayOffset() + buf.position() + offset, length, charset); } buf = buf.slice(); buf.limit(length); buf.position(offset); return copiedBuffer(buf, charset); } return copiedBuffer(CharBuffer.wrap(string, offset, offset + length), charset); }
/** Returns a new CharBuffer identical to buf, except twice the capacity. */ private static CharBuffer grow(CharBuffer buf) { char[] copy = Arrays.copyOf(buf.array(), buf.capacity() * 2); CharBuffer bigger = CharBuffer.wrap(copy); bigger.position(buf.position()); bigger.limit(buf.limit()); return bigger; }
private int getArray(CharBuffer in) { if (in.hasArray()) { input = in.array(); inEnd = in.arrayOffset() + in.limit(); return in.arrayOffset() + in.position(); } else { inEnd = in.remaining(); if (allocatedInput == null || inEnd > allocatedInput.length) { allocatedInput = new char[inEnd]; } // Copy the input buffer into the allocated array. int pos = in.position(); in.get(allocatedInput, 0, inEnd); in.position(pos); // The array's start position is 0 input = allocatedInput; return 0; } }
@Nullable @Override public char[] deobfuscatePassword(@Nullable ByteArrayRuntimeObfuscator obfuscated) { if (obfuscated == null) return null; CharBuffer charBuffer = StandardCharsets.UTF_8.decode(ByteBuffer.wrap(obfuscated.getBytes())); if (charBuffer.capacity() != charBuffer.limit()) { char[] compacted = new char[charBuffer.remaining()]; charBuffer.get(compacted); return compacted; } return charBuffer.array(); }
private void expandBuffer() { int oldPosition = buffer.position(); int oldCapacity = buffer.capacity(); int oldLimit = buffer.limit(); int newCapacity = oldCapacity * 2; char[] newBuffer = new char[newCapacity]; System.arraycopy(buffer.array(), 0, newBuffer, 0, oldLimit); buffer = CharBuffer.wrap(newBuffer, 0, newCapacity); buffer.position(oldPosition); buffer.limit(oldLimit); }
/** * Creates a new big-endian buffer whose content is a subregion of * the specified {@code string} encoded in the specified {@code charset}. * The new buffer's {@code readerIndex} and {@code writerIndex} are * {@code 0} and the length of the encoded string respectively. */ public static ByteBuf copiedBuffer( CharSequence string, int offset, int length, Charset charset) { if (string == null) { throw new NullPointerException("string"); } if (length == 0) { return EMPTY_BUFFER; } if (string instanceof CharBuffer) { CharBuffer buf = (CharBuffer) string; if (buf.hasArray()) { return copiedBuffer( buf.array(), buf.arrayOffset() + buf.position() + offset, length, charset); } buf = buf.slice(); buf.limit(length); buf.position(offset); return copiedBuffer(buf, charset); } return copiedBuffer(CharBuffer.wrap(string, offset, offset + length), charset); }