1121N/A/*
2362N/A * Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved.
1121N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1121N/A *
1121N/A * This code is free software; you can redistribute it and/or modify it
1121N/A * under the terms of the GNU General Public License version 2 only, as
1121N/A * published by the Free Software Foundation.
1121N/A *
1121N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1121N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1121N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1121N/A * version 2 for more details (a copy is included in the LICENSE file that
1121N/A * accompanied this code).
1121N/A *
1121N/A * You should have received a copy of the GNU General Public License version
1121N/A * 2 along with this work; if not, write to the Free Software Foundation,
1121N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1121N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1121N/A */
1121N/A
1121N/Aimport java.io.*;
1121N/Aimport java.awt.*;
1121N/A
1121N/Apublic class DeleteFont {
1121N/A
1121N/A public static void main(String args[]) throws Exception {
1121N/A
1121N/A String font = "A.ttf";
1121N/A String sep = System.getProperty("file.separator");
1121N/A String testSrc = System.getenv("TESTSRC");
1121N/A if (testSrc != null) {
1121N/A font = testSrc + sep + font;
1121N/A }
1121N/A System.out.println("Using font file: " + font);
1121N/A FileInputStream fis = new FileInputStream(font);
1121N/A Font f = Font.createFont(Font.TRUETYPE_FONT, fis);
1121N/A f.toString();
1121N/A f.deriveFont(Font.BOLD);
1121N/A f.canDisplay('X');
1121N/A
1121N/A InputStream in = new InputStream() {
1121N/A public int read() {
1121N/A throw new RuntimeException();
1121N/A }
1121N/A };
1121N/A boolean gotException = false;
1121N/A try {
1121N/A Font.createFont(java.awt.Font.TRUETYPE_FONT, in);
1121N/A } catch (IOException e) {
1121N/A gotException = true;
1121N/A }
1121N/A if (!gotException) {
1121N/A throw new RuntimeException("No expected IOException");
1121N/A }
1124N/A badRead(-2, Font.TRUETYPE_FONT);
1124N/A badRead(8193, Font.TRUETYPE_FONT);
1124N/A
1124N/A badRead(-2, Font.TYPE1_FONT);
1124N/A badRead(8193, Font.TYPE1_FONT);
1124N/A
1124N/A // Make sure GC has a chance to clean up before we exit.
1124N/A System.gc(); System.gc();
1121N/A }
1121N/A
1124N/A static void badRead(final int retval, int fontType) {
1121N/A int num = 2;
1121N/A byte[] buff = new byte[16*8192]; // Multiple of 8192 is important.
1121N/A for (int ct=0; ct<num; ++ct) {
1121N/A try {
1121N/A Font.createFont(
1124N/A fontType,
1121N/A new ByteArrayInputStream(buff) {
1121N/A @Override
1121N/A public int read(byte[] buff, int off, int len) {
1121N/A int read = super.read(buff, off, len);
1121N/A return read<0 ? retval : read;
1121N/A }
1121N/A }
1121N/A );
1121N/A } catch (Throwable exc) {
1121N/A //exc.printStackTrace();
1121N/A }
1121N/A }
1121N/A }
1121N/A}
1121N/A