/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.
*/ package org.apache.catalina.util;
/** * Read input from reader and write it to writer until there is no more * input from reader. * * @param reader the reader to read from. * @param writer the writer to write to. * @param buf the char array to use as a buffer * @throws IOException IO error
*/ publicstaticvoid flow( Reader reader, Writer writer, char[] buf ) throws IOException { int numRead; while ( (numRead = reader.read(buf) ) >= 0) {
writer.write(buf, 0, numRead);
}
}
/** * Read input from reader and write it to writer until there is no more * input from reader. * * @param reader the reader to read from. * @param writer the writer to write to. * @throws IOException IO error * @see #flow( Reader, Writer, char[] )
*/ publicstaticvoid flow( Reader reader, Writer writer ) throws IOException { char[] buf = newchar[DEFAULT_BUFFER_SIZE];
flow( reader, writer, buf );
}
/** * Read input from input stream and write it to output stream until there is * no more input from input stream using a new buffer of the default size * (4 KiB). * * @param is input stream the input stream to read from. * @param os output stream the output stream to write to. * * @throws IOException If an I/O error occurs during the copy
*/ publicstaticvoid flow(InputStream is, OutputStream os) throws IOException { byte[] buf = newbyte[DEFAULT_BUFFER_SIZE]; int numRead; while ( (numRead = is.read(buf) ) >= 0) { if (os != null) {
os.write(buf, 0, numRead);
}
}
}
/** * Read until EOF or the buffer is filled. * * @param is The source to read from * @param buf The buffer to write to * * @return The number of bytes read * * @throws IOException If an I/O error occurs during the read
*/ publicstaticint readFully(InputStream is, byte[] buf) throws IOException { int bytesRead = 0; int read; while (bytesRead < buf.length && ((read = is.read(buf, bytesRead, buf.length - bytesRead)) >= 0)) {
bytesRead += read;
} return bytesRead;
}
}
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.