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