/** * Replace a region of bytes in this ByteList with a region of bytes from the given array. * * @param targetOff offset of target region in this ByteList * @param targetLen length of target region in this ByteList * @param source bytes to use for replacement * @param sourceOff offset of source region in the replacement bytes * @param sourceLen length of source region in the replacement bytes */ public void replace(int targetOff, int targetLen, byte[] source, int sourceOff, int sourceLen) { int newSize = realSize - targetLen + sourceLen; ensure(newSize); int tailSize = realSize - (targetLen + targetOff); if (tailSize != 0) { System.arraycopy(bytes,begin+targetOff+targetLen,bytes,begin+targetOff+sourceLen,tailSize); } if (sourceLen != 0) { System.arraycopy(source,sourceOff,bytes,begin+targetOff,sourceLen); } realSize = newSize; invalidate(); }
/** * Replace a region of bytes in this ByteList with a region of bytes from the given array. * * @param targetOff offset of target region in this ByteList * @param targetLen length of target region in this ByteList * @param source bytes to use for replacement * @param sourceOff offset of source region in the replacement bytes * @param sourceLen length of source region in the replacement bytes */ public void replace(int targetOff, int targetLen, byte[] source, int sourceOff, int sourceLen) { int newSize = realSize - targetLen + sourceLen; ensure(newSize); int tailSize = realSize - (targetLen + targetOff); if (tailSize != 0) { System.arraycopy(bytes,begin+targetOff+targetLen,bytes,begin+targetOff+sourceLen,tailSize); } if (sourceLen != 0) { System.arraycopy(source,sourceOff,bytes,begin+targetOff,sourceLen); } realSize = newSize; invalidate(); }
@Override public int resize(ByteList destination, int len, int new_len) { destination.setRealSize(len); destination.ensure(new_len); return destination.getBegin(); } };
@Override public int resize(ByteList destination, int len, int new_len) { destination.setRealSize(len); destination.ensure(new_len); return destination.getBegin(); } };
public static void strBufCat(ByteList str, byte[] ptrBytes, int ptr, int len) { int total, off = -1; // termlen is not relevant since we have no termination sequence // missing: if ptr string is inside str, off = ptr start minus str start // str.modify(); if (len == 0) return; // much logic is missing here, since we don't manually manage the ByteList buffer total = str.getRealSize() + len; str.ensure(total); str.append(ptrBytes, ptr, len); }
public static void strBufCat(ByteList str, byte[] ptrBytes, int ptr, int len) { int total, off = -1; // termlen is not relevant since we have no termination sequence // missing: if ptr string is inside str, off = ptr start minus str start // str.modify(); if (len == 0) return; // much logic is missing here, since we don't manually manage the ByteList buffer total = str.getRealSize() + len; str.ensure(total); str.append(ptrBytes, ptr, len); }
/** rb_str_modify (with length bytes ensured) * */ public final void modify(int length) { modifyCheck(); if (shareLevel != SHARE_LEVEL_NONE) { if (shareLevel == SHARE_LEVEL_BYTELIST) { value = value.dup(length); } else { value.unshare(length); } shareLevel = SHARE_LEVEL_NONE; } else { value.ensure(length); } value.invalidate(); }
/** rb_str_modify (with length bytes ensured) * */ public final void modify(int length) { modifyCheck(); if (shareLevel != SHARE_LEVEL_NONE) { if (shareLevel == SHARE_LEVEL_BYTELIST) { value = value.dup(length); } else { value.unshare(length); } shareLevel = SHARE_LEVEL_NONE; } else { value.ensure(length); } value.invalidate(); }
/** rb_str_modify (with length bytes ensured) * */ public final void modify(int length) { modifyCheck(); if (shareLevel != SHARE_LEVEL_NONE) { if (shareLevel == SHARE_LEVEL_BYTELIST) { value = value.dup(length); } else { value.unshare(length); } shareLevel = SHARE_LEVEL_NONE; } else { value.ensure(length); } value.invalidate(); }
/** rb_str_modify (with length bytes ensured) * */ public final void modify(int length) { modifyCheck(); if (shareLevel != SHARE_LEVEL_NONE) { if (shareLevel == SHARE_LEVEL_BYTELIST) { value = value.dup(length); } else { value.unshare(length); } shareLevel = SHARE_LEVEL_NONE; } else { value.ensure(length); } value.invalidate(); }
/** rb_str_modify (with length bytes ensured) * */ public final void modify(int length) { modifyCheck(); if (shareLevel != SHARE_LEVEL_NONE) { if (shareLevel == SHARE_LEVEL_BYTELIST) { value = value.dup(length); } else { value.unshare(length); } shareLevel = SHARE_LEVEL_NONE; } else { value.ensure(length); } value.invalidate(); }
public static void strBufCat(Ruby runtime, RubyString str, ByteList ptr) { int total, off = -1; // termlen is not relevant since we have no termination sequence // missing: if ptr string is inside str, off = ptr start minus str start str.modify(); if (ptr.length() == 0) return; // much logic is missing here, since we don't manually manage the ByteList buffer total = str.size() + ptr.length(); str.getByteList().ensure(total); str.getByteList().append(ptr); }
public static void strBufCat(Ruby runtime, RubyString str, ByteList ptr) { int total, off = -1; // termlen is not relevant since we have no termination sequence // missing: if ptr string is inside str, off = ptr start minus str start str.modify(); if (ptr.length() == 0) return; // much logic is missing here, since we don't manually manage the ByteList buffer total = str.size() + ptr.length(); str.getByteList().ensure(total); str.getByteList().append(ptr); }
/** * Perform a low-level read of the specified number of bytes into the specified * byte list. The incoming bytes will be appended to the byte list. This is * equivalent to the read(2) POSIX function, and like that function it * ignores read and write buffers defined elsewhere. * * @param number the number of bytes to read * @param byteList the byte list on which to append the incoming bytes * @return the number of bytes actually read * @throws java.io.IOException if there is an exception during IO * @throws org.jruby.util.io.BadDescriptorException if the associated * channel is already closed. * @see org.jruby.util.ByteList */ public int read(int number, ByteList byteList) throws IOException, BadDescriptorException { checkOpen(); byteList.ensure(byteList.length() + number); int bytesRead = read(ByteBuffer.wrap(byteList.getUnsafeBytes(), byteList.begin() + byteList.length(), number)); if (bytesRead > 0) { byteList.length(byteList.length() + bytesRead); } return bytesRead; }
/** * This looks deceptively like tokadd_mbchar(int, ByteList) but it differs in that it uses * the bytelists encoding and the first parameter is a full codepoint and not the first byte * of a mbc sequence. */ public void tokaddmbc(int codepoint, ByteList buffer) { Encoding encoding = buffer.getEncoding(); int length = encoding.codeToMbcLength(codepoint); buffer.ensure(buffer.getRealSize() + length); encoding.codeToMbc(codepoint, buffer.getUnsafeBytes(), buffer.begin() + buffer.getRealSize()); buffer.setRealSize(buffer.getRealSize() + length); }
/** * This looks deceptively like tokadd_mbchar(int, ByteList) but it differs in that it uses * the bytelists encoding and the first parameter is a full codepoint and not the first byte * of a mbc sequence. */ public void tokaddmbc(int codepoint, ByteList buffer) { Encoding encoding = buffer.getEncoding(); int length = encoding.codeToMbcLength(codepoint); buffer.ensure(buffer.getRealSize() + length); encoding.codeToMbc(codepoint, buffer.getUnsafeBytes(), buffer.begin() + buffer.getRealSize()); buffer.setRealSize(buffer.getRealSize() + length); }
@Override public void visit(ThreadContext context, RubyHash self, IRubyObject key, IRubyObject value, int index, RubyString str) { RubyString keyStr = inspect(context, key); RubyString valStr = inspect(context, value); final ByteList bytes = str.getByteList(); bytes.ensure(2 + keyStr.size() + 2 + valStr.size()); if (index > 0) bytes.append((byte) ',').append((byte) ' '); str.cat19(keyStr); bytes.append((byte) '=').append((byte) '>'); str.cat19(valStr); } };
@Override public void visit(ThreadContext context, RubyHash self, IRubyObject key, IRubyObject value, int index, RubyString str) { RubyString keyStr = inspect(context, key); RubyString valStr = inspect(context, value); final ByteList bytes = str.getByteList(); bytes.ensure(2 + keyStr.size() + 2 + valStr.size()); if (index > 0) bytes.append((byte) ',').append((byte) ' '); str.cat19(keyStr); bytes.append((byte) '=').append((byte) '>'); str.cat19(valStr); } };
@Override protected IRubyObject inspectAry(ThreadContext context) { if (!packed()) return super.inspectAry(context); final Ruby runtime = context.runtime; RubyString str = RubyString.newStringLight(runtime, DEFAULT_INSPECT_STR_SIZE, USASCIIEncoding.INSTANCE); str.cat((byte) '['); boolean tainted = isTaint(); RubyString s1 = inspect(context, car); RubyString s2 = inspect(context, cdr); if (s1.isTaint()) tainted = true; else str.setEncoding(s1.getEncoding()); str.cat19(s1); ByteList bytes = str.getByteList(); bytes.ensure(2 + s2.size() + 1); bytes.append((byte) ',').append((byte) ' '); if (s2.isTaint()) tainted = true; else str.setEncoding(s2.getEncoding()); str.cat19(s2); str.cat((byte) ']'); if (tainted) str.setTaint(true); return str; }
@Override protected IRubyObject inspectAry(ThreadContext context) { if (!packed()) return super.inspectAry(context); final Ruby runtime = context.runtime; RubyString str = RubyString.newStringLight(runtime, DEFAULT_INSPECT_STR_SIZE, USASCIIEncoding.INSTANCE); str.cat((byte) '['); boolean tainted = isTaint(); RubyString s1 = inspect(context, car); RubyString s2 = inspect(context, cdr); if (s1.isTaint()) tainted = true; else str.setEncoding(s1.getEncoding()); str.cat19(s1); ByteList bytes = str.getByteList(); bytes.ensure(2 + s2.size() + 1); bytes.append((byte) ',').append((byte) ' '); if (s2.isTaint()) tainted = true; else str.setEncoding(s2.getEncoding()); str.cat19(s2); str.cat((byte) ']'); if (tainted) str.setTaint(true); return str; }