/** * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * See the NOTICE file distributed with this work for additional * information regarding copyright ownership. */ package org.sintef.thingml.resource.thingml.util; public class ThingmlStreamUtil { private final static int IO_BUFFER_SIZE = 4 * 1024; public static void copy(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOException { byte[] b = new byte[IO_BUFFER_SIZE]; int read; while ((read = in.read(b)) != -1) { out.write(b, 0, read); } out.flush(); } public static String getContent(java.io.InputStream inputStream) throws java.io.IOException { StringBuffer content = new StringBuffer(); java.io.InputStreamReader reader = new java.io.InputStreamReader(inputStream); int next = -1; while ((next = reader.read()) >= 0) { content.append((char) next); } return content.toString(); } }