// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.io.reader;

import com.google.common.annotations.Beta;

import java.io.IOException;
import java.io.Reader;
import java.util.List;

/**
 * A reader with a name. All reader methods are delegated to the wrapped reader.
 *
 * @author bratseth
 */
@Beta
public class NamedReader extends Reader {

    private final String name;
    private final Reader reader;

    public NamedReader(String name, Reader reader) {
        this.name = name;
        this.reader = reader;
    }

    public String getName() { return name; }

    public Reader getReader() { return reader; }

    /** Returns the name */
    public @Override String toString() {
        return name;
    }

    // The rest is reader method implementations which delegates to the wrapped reader
    public @Override int read(java.nio.CharBuffer charBuffer) throws java.io.IOException { return reader.read(charBuffer); }
    public @Override int read() throws java.io.IOException { return reader.read(); }
    public @Override int read(char[] chars) throws java.io.IOException { return reader.read(chars); }
    public @Override int read(char[] chars, int i, int i1) throws java.io.IOException { return reader.read(chars,i,i1); }
    public @Override long skip(long l) throws java.io.IOException { return reader.skip(l); }
    public @Override boolean ready() throws java.io.IOException { return reader.ready(); }
    public @Override boolean markSupported() { return reader.markSupported(); }
    public @Override void mark(int i) throws java.io.IOException { reader.mark(i); }
    public @Override void reset() throws java.io.IOException { reader.reset(); }
    public @Override void close() throws java.io.IOException { reader.close(); }

    /** Convenience method for closing a list of readers. Does nothing if the given reader list is null. */
    public static void closeAll(List<NamedReader> readers) {
        if (readers==null) return;
        for (Reader reader : readers) {
            try {
                reader.close();
            }
            catch (IOException e) {
                // Nothing to do about it
            }
        }
    }

}
@@ -722,31 +722,24 @@
 name */%0A    
-public 
 @Override St
@@ -735,16 +735,27 @@
 Override
+%0A    public
  String 
@@ -882,31 +882,24 @@
  reader%0A    
-public 
 @Override in
@@ -887,32 +887,43 @@
 er%0A    @Override
+%0A    public
  int read(java.n
@@ -1007,39 +1007,32 @@
 rBuffer); %7D%0A    
-public 
 @Override int re
@@ -1016,32 +1016,43 @@
  %7D%0A    @Override
+%0A    public
  int read() thro
@@ -1096,39 +1096,32 @@
 r.read(); %7D%0A    
-public 
 @Override int re
@@ -1105,32 +1105,43 @@
  %7D%0A    @Override
+%0A    public
  int read(char%5B%5D
@@ -1202,39 +1202,32 @@
 d(chars); %7D%0A    
-public 
 @Override int re
@@ -1219,16 +1219,27 @@
 Override
+%0A    public
  int rea
@@ -1328,39 +1328,32 @@
 rs,i,i1); %7D%0A    
-public 
 @Override long s
@@ -1345,16 +1345,27 @@
 Override
+%0A    public
  long sk
@@ -1425,39 +1425,32 @@
 .skip(l); %7D%0A    
-public 
 @Override boolea
@@ -1434,32 +1434,43 @@
  %7D%0A    @Override
+%0A    public
  boolean ready()
@@ -1520,39 +1520,32 @@
 .ready(); %7D%0A    
-public 
 @Override boolea
@@ -1537,16 +1537,27 @@
 Override
+%0A    public
  boolean
@@ -1604,39 +1604,32 @@
 ported(); %7D%0A    
-public 
 @Override void m
@@ -1617,24 +1617,35 @@
    @Override
+%0A    public
  void mark(i
@@ -1693,39 +1693,32 @@
 .mark(i); %7D%0A    
-public 
 @Override void r
@@ -1706,24 +1706,35 @@
    @Override
+%0A    public
  void reset(
@@ -1786,23 +1786,16 @@
 ; %7D%0A    
-public 
 @Overrid
@@ -1795,16 +1795,27 @@
 Override
+%0A    public
  void cl

move override annotation