< prev index next >

test/jdk/java/awt/FontClass/CreateFont/BigFont.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2018, 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.

@@ -19,16 +19,27 @@
  * 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.
  */
 
-import java.applet.*;
-import java.awt.*;
-import java.io.*;
-import java.net.*;
-
-public class BigFont extends Applet {
+import java.awt.Font;
+import java.awt.FontFormatException;
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.nio.file.Paths;
+
+/**
+ * @test
+ * @key headful
+ * @bug 6522586
+ * @summary Enforce limits on font creation
+ * @run main BigFont 1 A.ttf
+ * @run main BigFont 2 A.ttf
+ */
+public class BigFont {
 
    static private class SizedInputStream extends InputStream {
 
        int size;
        int cnt = 0;

@@ -49,16 +60,16 @@
        public int getCurrentSize() {
            return cnt;
        }
    }
 
-    String id;
-    String fileName;
+    static String id;
+    static String fileName;
 
-    public void init() {
-        id = getParameter("number");
-        fileName = getParameter("font");
+    public static void main(final String[] args) {
+        id = args[0];
+        fileName = args[1];
 
         System.out.println("Applet " + id + " "+
                            Thread.currentThread().getThreadGroup());
         if (System.getSecurityManager() == null) {
             System.setSecurityManager(new SecurityManager());

@@ -100,11 +111,14 @@
         System.out.println("Applet " + id + " finished.");
     }
 
     int getFileSize(String fileName) {
         try {
-            URL url = new URL(getCodeBase(), fileName);
+            String path = Paths.get(System.getProperty("test.src", "."),
+                                    fileName).toAbsolutePath().normalize()
+                                             .toString();
+            URL url = new URL(path);
             InputStream inStream = url.openStream();
             BufferedInputStream fontStream = new BufferedInputStream(inStream);
             int size = 0;
             while (fontStream.read() != -1) {
                 size++;

@@ -121,11 +135,14 @@
         Font[] fonts = new Font[fontCnt];
         int totalSize = 0;
         boolean gotException = false;
         for (int i=0; i<fontCnt; i++) {
             try {
-                URL url = new URL(getCodeBase(), fileName);
+                String path = Paths.get(System.getProperty("test.src", "."),
+                                        fileName).toAbsolutePath().normalize()
+                                                 .toString();
+                URL url = new URL(path);
                 InputStream inStream = url.openStream();
                 BufferedInputStream fontStream =
                     new BufferedInputStream(inStream);
                 fonts[i] = Font.createFont(Font.TRUETYPE_FONT, fontStream);
                 totalSize += oneFont;
< prev index next >