Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8120580

Font#loadFont() closes InputStream on J2D pipeline

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 7u6
    • Fix Version/s: 7u6
    • Component/s: javafx
    • Labels:

      Description

      Snippet:
      public void start(Stage stage) throws Exception {
          String fontfile = "/Users/felipe/Documents/fonts/JandaElegantHandwriting.ttf";
          Font font = null;
          InputStream inputStream = null;
          try {
              FileInputStream fileStream = new FileInputStream(fontfile);
              inputStream = new BufferedInputStream(fileStream);
              inputStream.mark(1024*1024);
              font = Font.loadFont(inputStream, 48);
              inputStream.reset();
              //reuse the input stream
          } catch (IOException e) {
              e.printStackTrace();
          } finally {
              if (inputStream != null) {
                  try {
                      inputStream.close();
                  } catch (IOException e) {}
              }
          }

          Text text = new Text("Hello World");
          text.setFont(font);
          VBox box = new VBox();
          box.getChildren().add(text);
          Scene scene = new Scene(box, 300, 300);
          stage.setTitle("My JavaFX Application");
          stage.setScene(scene);
          stage.show();
      }

      In the J2D pipeline the call to inputStream.reset() will fail because the input stream is closed, this is an error since the javadoc for Font#loadFont(InputStream, double) explicitly says the stream will not be closed.

        Attachments

          Activity

            People

            • Assignee:
              fheidric Felipe Heidrich (Inactive)
              Reporter:
              fheidric Felipe Heidrich (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: