将Reader中的内容复制到Writer中 使用默认缓存大小

@param reader Reader
@param writer Writer
@return 拷贝的字节数
@throws IORuntimeException IO异常
323185
public static long copy(Reader reader, Writer writer) throws IORuntimeException {
		return copy(reader, writer, DEFAULT_BUFFER_SIZE);
	}
392614
public static String readerAsString(Reader reader) {
    StringBuilder buffer = new StringBuilder();
    char[] chars = new char[16 * 1024];
    int numCharsRead;
    try {
      while ((numCharsRead = reader.read(chars, 0, chars.length)) != -1) {
        buffer.append(chars, 0, numCharsRead);
      }
      return buffer.toString();
    } catch (IOException e) {
      throw LOG.unableToReadFromReader(e);
    }
    finally {
      closeSilently(reader);
    }
  }
1187021
public CsvData read(Reader reader) throws IORuntimeException {
		final CsvParser csvParser = parse(reader);

		final List<CsvRow> rows = new ArrayList<>();
		CsvRow csvRow;
		while ((csvRow = csvParser.nextRow()) != null) {
			rows.add(csvRow);
		}

		final List<String> header = config.containsHeader ? csvParser.getHeader() : null;
		return new CsvData(header, rows);
	}
1008269
public static <T> byte[] write(Buffer.Writer<T> writer, T value) {
    Buffer b = Buffer.allocate(writer.sizeInBytes(value));
    try {
      writer.write(value, b);
    } catch (RuntimeException e) {
      byte[] bytes = b.toByteArray();
      int lengthWritten = bytes.length;
      for (int i = 0; i < bytes.length; i++) {
        if (bytes[i] == 0) {
          lengthWritten = i;
          break;
        }
      }

      final byte[] bytesWritten;
      if (lengthWritten == bytes.length) {
        bytesWritten = bytes;
      } else {
        bytesWritten = new byte[lengthWritten];
        System.arraycopy(bytes, 0, bytesWritten, 0, lengthWritten);
      }

      String written = new String(bytesWritten, UTF_8);
      // Don't use value directly in the message, as its toString might be implemented using this
      // method. If that's the case, we'd stack overflow. Instead, emit what we've written so far.
      String message =
        format(
          "Bug found using %s to write %s as json. Wrote %s/%s bytes: %s",
          writer.getClass().getSimpleName(),
          value.getClass().getSimpleName(),
          lengthWritten,
          bytes.length,
          written);
      throw Platform.get().assertionError(message, e);
    }
    return b.toByteArray();
  }
227410
private static String readStreamIntoString(Reader reader) throws IOException
   {
      StringBuilder s = new StringBuilder();
      char a[] = new char[0x10000];
      while (true)
      {
         int l = reader.read(a);
         if (l == -1)
            break;
         if (l <= 0)
            throw new IOException();
         s.append(a, 0, l);
      }
      return s.toString();
   }
558308
public static void copy(InputStream in, Writer writer) throws IOException {
    copy(getInputStreamReader(in), writer);
    writer.flush();
  }
449872
static public void copyStream(Reader reader, Writer writer, int transferBufferSize) throws IOException {
		if( transferBufferSize < 1 ) {
			throw new IOException("Transfer buffer size can not be smaller than 1");
		}

		char[] buffer = new char[transferBufferSize];

		int bytesRead = reader.read(buffer);
		while( bytesRead >= 0 ) {
			writer.write(buffer, 0, bytesRead);

			bytesRead = reader.read(buffer);
		}
	}
183839
public void write(Reader reader, boolean escape, boolean noBackslashEscapes) throws IOException {
    char[] buffer = new char[4096];
    int len;
    while ((len = reader.read(buffer)) >= 0) {
      byte[] data = new String(buffer, 0, len).getBytes("UTF-8");
      if (escape) {
        writeBytesEscaped(data, data.length, noBackslashEscapes);
      } else {
        write(data);
      }

    }
  }
564115
public static void write2File(final Reader reader, final Writer writer) throws IOException
	{
		int byt;
		while ((byt = reader.read()) != -1)
		{
			writer.write(byt);
		}
	}
1184585
public final boolean fill(CharacterBuffer buffer, Reader reader) throws IOException {
    return fill(buffer, reader, buffer.buffer.length);
  }
822189
private static Writer writerFor( OutputStream stream)
    {
    try
      {
      return
        stream == null
        ? null
        : new OutputStreamWriter( stream, "UTF-8");
      }
    catch( Exception e)
      {
      throw new RuntimeException( "Can't create writer", e);
      }
    }
487634
public static int copy(Reader reader, Writer writer, boolean closeWriter) {
        if (closeWriter) {
            return write(reader).ensureCloseSink().to(writer);
        } else {
            return write(reader).to(writer);
        }
    }
771075
public static long copy(Reader reader, Writer writer, int bufferSize) throws IORuntimeException {
		return copy(reader, writer, bufferSize, null);
	}
1268969
public static void copy(Reader in,
                            Writer out,
                            long byteCount)
         throws IOException
    {  
        char buffer[] = new char[bufferSize];
        int len=bufferSize;
        
        if (byteCount>=0)
        {
            while (byteCount>0)
            {
                if (byteCount<bufferSize)
                    len=in.read(buffer,0,(int)byteCount);
                else
                    len=in.read(buffer,0,bufferSize);                   
                
                if (len==-1)
                    break;
                
                byteCount -= len;
                out.write(buffer,0,len);
            }
        }
        else
        {
            while (true)
            {
                len=in.read(buffer,0,bufferSize);
                if (len==-1)
                    break;
                out.write(buffer,0,len);
            }
        }
    }
896148
public static String read(Reader reader) {
        StringWriter writer = new StringWriter();
        try {
            char[] buffer = new char[DEFAULT_BUFFER_SIZE];
            int n;
            while (-1 != (n = reader.read(buffer))) {
                writer.write(buffer, 0, n);
            }

            return writer.toString();
        } catch (IOException ex) {
            throw new IllegalStateException("read error", ex);
        }
    }
967725
public StreamImpl openReadWriteImpl() throws IOException
  {
    HttpStreamWrapper stream = HttpStream.openReadWrite(this);

    stream.setSSL(true);
    
    return stream;
  }
898891
public static StringBlock read(IntReader reader) throws IOException {
        ReadUtil.readCheckType(reader,CHUNK_TYPE);
        int chunkSize=reader.readInt();
        int stringCount=reader.readInt();
        int styleOffsetCount=reader.readInt();
        int flags = reader.readInt();
        int stringsOffset=reader.readInt();
        int stylesOffset=reader.readInt();

        StringBlock block=new StringBlock();
        block.m_stringOffsets=reader.readIntArray(stringCount);
        if (styleOffsetCount!=0) {
            block.m_styleOffsets=reader.readIntArray(styleOffsetCount);
        }
        {
            int size=((stylesOffset==0)?chunkSize:stylesOffset)-stringsOffset;
            if ((size%4)!=0) {
                throw new IOException("String data size is not multiple of 4 ("+size+").");
            }
            block.m_stringPool =reader.readByteArray(size);
        }
        if (stylesOffset!=0) {
            int size=(chunkSize-stylesOffset);
            if ((size%4)!=0) {
                throw new IOException("Style data size is not multiple of 4 ("+size+").");
            }
            block.m_styles=reader.readIntArray(size/4);
        }

        // Set field flag to determine if stored in UTF-8 (or false for UTF-16).
        block.m_isUtf8 = (flags & UTF8_FLAG) == UTF8_FLAG;

        block.m_strings =new String[block.getCount()];
        for (int i=0;i!=block.getCount();++i) {
            block.m_strings[i]=block.stringAt(i);
        }

        return block;
    }