/* * Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
privatestaticvoid readAndCheck(File blah) throws Exception {
FileInputStream fis = new FileInputStream(blah); int messageSize = message.length() * ITERATIONS * 3 + 1; byte bb[] = newbyte[messageSize]; int bytesRead = 0; int totalRead = 0; while (bytesRead != -1) {
totalRead += bytesRead;
bytesRead = fis.read(bb, totalRead, messageSize - totalRead);
}
String result = new String(bb, 0, totalRead, encoding); int len = message.length(); for (int i=0; i<ITERATIONS; i++) {
String segment = result.substring(i++ * len, i * len); if (!segment.equals(message)) thrownew RuntimeException("Test failed");
}
fis.close();
}
privatestaticvoid writeOut(File blah, int limit) throws Exception {
FileOutputStream fos = new FileOutputStream(blah); for (int i=0; i<limit; i++)
fos.write(message.getBytes(encoding));
fos.close();
}
privatestaticvoid testNewOutputStream(File blah) throws Exception {
FileOutputStream fos = new FileOutputStream(blah);
FileChannel fc = fos.getChannel();
WritableByteChannel wbc = (WritableByteChannel)fc;
OutputStream os = Channels.newOutputStream(wbc); for (int i=0; i<ITERATIONS; i++)
os.write(message.getBytes(encoding));
os.close();
fos.close();
}
privatestaticvoid testNewInputStream(File blah) throws Exception {
FileInputStream fis = new FileInputStream(blah);
FileChannel fc = fis.getChannel();
InputStream is = Channels.newInputStream(fc); int messageSize = message.length() * ITERATIONS * 3 + 1; byte bb[] = newbyte[messageSize];
int bytesRead = 0; int totalRead = 0; while (bytesRead != -1) {
totalRead += bytesRead; long rem = Math.min(fc.size() - totalRead, (long)Integer.MAX_VALUE); if (is.available() != (int)rem) thrownew RuntimeException("available not useful or not maximally useful");
bytesRead = is.read(bb, totalRead, messageSize - totalRead);
} if (is.available() != 0) thrownew RuntimeException("available() should return 0 at EOF");
String result = new String(bb, 0, totalRead, encoding); int len = message.length(); for (int i=0; i<ITERATIONS; i++) {
String segment = result.substring(i++ * len, i * len); if (!segment.equals(message)) thrownew RuntimeException("Test failed");
}
is.close();
fis.close();
}
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.