Ejemplo n.º 1
0
 /// <summary>
 /// This will add a <c>String</c> to the end of the buffer.
 /// The buffer will not overflow with repeated uses of the
 /// <c>append</c>, it uses an <c>ensureCapacity</c>
 /// method which will allow the buffer to dynamically grow in
 /// size to accomodate large <c>String</c> objects.
 /// </summary>
 /// <param name="str">
 /// the <c>String</c> to be appended to this
 /// </param>
 /// <param name="off">
 /// the read offset for the <c>String</c>
 /// </param>
 /// <param name="len">
 /// the number of characters to append to this
 /// </param>
 public void Append(String str, int off, int len) {
    EnsureCapacity(count+ len);
    str.getChars(off,len,buf,count);
    count += len;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// This will add a <c>String</c> to the end of the buffer.
 /// The buffer will not overflow with repeated uses of the
 /// <c>append</c>, it uses an <c>ensureCapacity</c>
 /// method which will allow the buffer to dynamically grow in
 /// size to accomodate large <c>String</c> objects.
 /// </summary>
 /// <param name="str">
 /// the <c>String</c> to be appended to this
 /// </param>
 public void Append(String str) {
    EnsureCapacity(count+ str.Length());
    str.getChars(0,str.Length(),buf,count);
    count += str.Length();
 }
Ejemplo n.º 3
0
 protected internal void replace0(int start, int end, String s)
 {
     if (start >= 0) {
         if (end > count) {
             end = count;
         }
         if (end > start) {
             int stringLength = s.length();
             int diff = end - start - stringLength;
             if (diff > 0) { // replacing with fewer characters
                 if (!shared) {
                     // index == count case is no-op
                     java.lang.SystemJ.arraycopy(value, end, value, start
                             + stringLength, count - end);
                 } else {
                     char[] newData = new char[value.Length];
                     java.lang.SystemJ.arraycopy(value, 0, newData, 0, start);
                     // index == count case is no-op
                     java.lang.SystemJ.arraycopy(value, end, newData, start
                             + stringLength, count - end);
                     value = newData;
                     shared = false;
                 }
             } else if (diff < 0) {
                 // replacing with more characters...need some room
                 move(-diff, end);
             } else if (shared) {
                 char[] clone = new char[value.Length];
                 SystemJ.arraycopy(value, 0, clone, 0, value.Length);
                 value = clone;
                 shared = false;
             }
             s.getChars(0, stringLength, value, start);
             count -= diff;
             return;
         }
         if (start == end) {
             if (s == null) {
                 throw new NullPointerException();
             }
             insert0(start, s);
             return;
         }
     }
     throw new StringIndexOutOfBoundsException();
 }
Ejemplo n.º 4
0
 protected internal void insert0(int index, String s)
 {
     if (0 <= index && index <= count) {
         if (s == null) {
             s = "null"; //$NON-NLS-1$
         }
         int min = s.length();
         if (min != 0) {
             move(min, index);
             s.getChars(0, min, value, index);
             count += min;
         }
     } else {
         throw new StringIndexOutOfBoundsException(index);
     }
 }
Ejemplo n.º 5
0
 protected internal void append0(String s)
 {
     if (s == null) {
         appendNull();
         return;
     }
     int adding = s.length();
     int newSize = count + adding;
     if (newSize > value.Length) {
         enlargeBuffer(newSize);
     }
     s.getChars(0, adding, value, count);
     count = newSize;
 }
Ejemplo n.º 6
0
 /**
  * Writes {@code count} characters starting at {@code offset} in {@code str}
  * to this writer. If {@code count} is greater than this writer's buffer,
  * then this writer is flushed and the remaining characters are written
  * directly to the target writer. If count is negative no characters are
  * written to the buffer. This differs from the behavior of the superclass.
  *
  * @param str
  *            the non-null String containing characters to write.
  * @param offset
  *            the start position in {@code str} for retrieving characters.
  * @param count
  *            maximum number of characters to write.
  * @throws IOException
  *             if this writer has already been closed or another I/O error
  *             occurs.
  * @throws IndexOutOfBoundsException
  *             if {@code offset &lt; 0} or {@code offset + count} is greater
  *             than the length of {@code str}.
  */
 public override void write(String str, int offset, int count)
 {
     //throws IOException {
     lock (lockJ)
     {
         if (isClosed())
         {
             throw new IOException("Writer is closed."); //$NON-NLS-1$
         }
         if (count <= 0)
         {
             return;
         }
         if (offset > str.length() - count || offset < 0)
         {
             throw new java.lang.StringIndexOutOfBoundsException();
         }
         if (pos == 0 && count >= buf.Length)
         {
             char[] chars = new char[count];
             str.getChars(offset, offset + count, chars, 0);
             outj.write(chars, 0, count);
             return;
         }
         int available = buf.Length - pos;
         if (count < available)
         {
             available = count;
         }
         if (available > 0)
         {
             str.getChars(offset, offset + available, buf, pos);
             pos += available;
         }
         if (pos == buf.Length)
         {
             outj.write(this.buf, 0, this.buf.Length);
             pos = 0;
             if (count > available)
             {
                 offset += available;
                 available = count - available;
                 if (available >= buf.Length)
                 {
                     char[] chars = new char[count];
                     str.getChars(offset, offset + available, chars, 0);
                     outj.write(chars, 0, available);
                     return;
                 }
                 str.getChars(offset, offset + available, buf, pos);
                 pos += available;
             }
         }
     }
 }
Ejemplo n.º 7
0
        /**
         * Writes {@code count} characters from {@code str} starting at {@code
         * offset} to the target.
         *
         * @param str
         *            the non-null string containing the characters to write.
         * @param offset
         *            the index of the first character in {@code str} to write.
         * @param count
         *            the number of characters from {@code str} to write.
         * @throws IOException
         *             if this writer is closed or another I/O error occurs.
         * @throws IndexOutOfBoundsException
         *             if {@code offset < 0} or {@code count < 0}, or if {@code
         *             offset + count} is greater than the length of {@code str}.
         */
        public virtual void write(String str, int offset, int count)
        {
            //throws IOException {
            if (count < 0)
            { // other cases tested by getChars()
                throw new java.lang.StringIndexOutOfBoundsException();
            }
            char[] buf = new char[count];
            str.getChars(offset, offset + count, buf, 0);

            lock (lockJ)
            {
                write(buf, 0, buf.Length);
            }
        }