/* * Copyright (c) 2006, 2020, 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.
*/
/** * @test * @bug 4679743 * @summary Test basic functionality of DeflaterInputStream and InflaterOutputStream * @key randomness
*/
reset(); for (;;) { int len = dis.read(buf, 0, buf.length); if (len <= 0) { break;
} else { for (int i = 0; i < len; i++) { byte x = (byte) (buf[i] & 0xff);
ios.write(x);
}
}
}
check(dis.available() == 0);
ios.close();
check(Arrays.equals(data, baos.toByteArray()));
}
/** Check single byte read, byte array write. * <p> * Note that this test relies on the vaule from DeflaterInputStream.read() * to determine when to stop reading.
*/ privatestaticvoid ByteReadArrayWrite() throws Throwable { byte[] buf = newbyte[8192]; int off = 0;
reset(); int datum = dis.read(); while (datum != -1) { if (off == 8192) {
ios.write(buf, 0, off);
off = 0;
}
buf[off++] = (byte) (datum & 0xff);
datum = dis.read();
} if (off > 0) {
ios.write(buf, 0, off);
}
ios.close();
check(Arrays.equals(data, baos.toByteArray()));
}
/** Check single byte read/write. * <p> * Note that this test relies on DeflaterInputStream.available() to * determine when to stop reading.
*/ privatestaticvoid ByteReadByteWrite() throws Throwable { byte[] buf = newbyte[512]; boolean reachEOF = false;
reset(); while (dis.available() == 1) { int datum = dis.read(); if (datum == -1) {
reachEOF = true;
} else { if (datum < 0 || datum > 255) {
fail("datum out of range: " + datum);
}
ios.write(datum);
}
}
dis.close();
ios.close();
check(data[0] == baos.toByteArray()[0]);
}
Inflater inf = reset(dict);
check(dis.available() == 1); boolean dictSet = false; for (;;) { int len = dis.read(buf, 0, buf.length); if (len < 0) { break;
} else { try {
ios.write(buf, 0, len); if (dictSet == false) {
check(false, "Must throw ZipException without dictionary"); return;
}
} catch (ZipException ze) {
check(dictSet == false, "Dictonary must be set only once");
check(checksum == inf.getAdler(), "Incorrect dictionary");
inf.setDictionary(dict); // After setting the dictionary, we have to flush the // InflaterOutputStream now in order to consume all the // pending input data from the last, failed call to "write()".
ios.flush();
dictSet = true;
}
}
}
check(dis.available() == 0);
ios.close();
check(Arrays.equals(data, baos.toByteArray()));
}
publicstaticvoid realMain(String[] args) throws Throwable { new Random(new Date().getTime()).nextBytes(data);
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 und die Messung sind noch experimentell.