You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2020/04/26 19:13:09 UTC

[GitHub] [commons-io] robtimus commented on a change in pull request #91: Support sub sequences in CharSequenceReader

robtimus commented on a change in pull request #91:
URL: https://github.com/apache/commons-io/pull/91#discussion_r415379568



##########
File path: src/main/java/org/apache/commons/io/input/CharSequenceReader.java
##########
@@ -37,22 +37,107 @@
     private int idx;
     private int mark;
 
+    /*
+     * end is an Integer instead of int because of backwards compatibility.
+     * When de-serializing a CharSequenceReader that was serialized before
+     * these two fields were added, they will be initialized to 0 and null
+     * respectively. If end was an int, it would be initialized to 0 as well.
+     * That would cause all de-serialized CharSequenceReaders to be empty.
+     */
+    private final int start;
+    private final Integer end;
+
     /**
      * Construct a new instance with the specified character sequence.
      *
      * @param charSequence The character sequence, may be {@code null}
      */
     public CharSequenceReader(final CharSequence charSequence) {
+        this(charSequence, 0);
+    }
+
+    /**
+     * Construct a new instance with a portion of the specified character sequence.
+     * <p>
+     * The start index is not strictly enforced to be within the bounds of the
+     * character sequence. This allows the character sequence to grow or shrink
+     * in size without risking any {@link IndexOutOfBoundsException} to be thrown.
+     * Instead, if the character sequence grows smaller than the start index, this
+     * instance will act as if all characters have been read.
+     * </p>
+     *
+     * @param charSequence The character sequence, may be {@code null}
+     * @param start The start index in the character sequence, inclusive
+     * @throws IllegalArgumentException if the start index is negative
+     * @since 2.7
+     */
+    public CharSequenceReader(final CharSequence charSequence, int start) {

Review comment:
       Fixed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org