RLPark 1.0.0
Reinforcement Learning Framework in Java

IOUtils.java

Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  * 
00009  *      http://www.apache.org/licenses/LICENSE-2.0
00010  * 
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 package rlpark.plugin.rltoys.experiments.scheduling.internal.messages;
00018 
00019 import java.io.ByteArrayOutputStream;
00020 import java.io.IOException;
00021 import java.io.InputStream;
00022 import java.io.OutputStream;
00023 import java.io.Reader;
00024 import java.io.Writer;
00025 
00067 public class IOUtils {
00073   private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
00074 
00089   static byte[] toByteArray(InputStream input) throws IOException {
00090     ByteArrayOutputStream output = new ByteArrayOutputStream();
00091     copy(input, output);
00092     return output.toByteArray();
00093   }
00094 
00118   private static int copy(InputStream input, OutputStream output) throws IOException {
00119     long count = copyLarge(input, output);
00120     if (count > Integer.MAX_VALUE) {
00121       return -1;
00122     }
00123     return (int) count;
00124   }
00125 
00144   private static long copyLarge(InputStream input, OutputStream output) throws IOException {
00145     byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
00146     long count = 0;
00147     int n = 0;
00148     while (-1 != (n = input.read(buffer))) {
00149       output.write(buffer, 0, n);
00150       count += n;
00151     }
00152     return count;
00153   }
00154 }
 All Classes Namespaces Files Functions Variables Enumerations
Zephyr
RLPark