modules/graphics/src/main/java/com/sun/javafx/css/Stylesheet.java

Print this page




 291      * @param source is the JavaFX .css file to convert
 292      * @param destination is the file to which the binary conversion is written
 293      * @throws IOException
 294      * @throws IllegalArgumentException if either parameter is null, if source and destination are the same,
 295      * if source cannot be read, or if destination cannot be written.
 296      */
 297     public static void convertToBinary(File source, File destination) throws IOException {
 298 
 299         if (source == null || destination == null) {
 300             throw new IllegalArgumentException("parameters may not be null");
 301         }
 302 
 303         if (source.getAbsolutePath().equals(destination.getAbsolutePath())) {
 304             throw new IllegalArgumentException("source and destination may not be the same");
 305         }
 306 
 307         if (source.canRead() == false) {
 308             throw new IllegalArgumentException("cannot read source file");
 309         }
 310 
 311         if ((destination.exists() && destination.canWrite() == false) || destination.createNewFile() == false) {
 312             throw new IllegalArgumentException("cannot write destination file");
 313         }
 314 
 315         URI sourceURI = source.toURI();
 316         Stylesheet stylesheet = CSSParser.getInstance().parse(sourceURI.toURL());
 317 
 318         // first write all the css binary data into the buffer and collect strings on way
 319         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 320         DataOutputStream dos = new DataOutputStream(baos);
 321         StringStore stringStore = new StringStore();
 322         stylesheet.writeBinary(dos, stringStore);
 323         dos.flush();
 324         dos.close();
 325 
 326         FileOutputStream fos = new FileOutputStream(destination);
 327         DataOutputStream os = new DataOutputStream(fos);
 328 
 329         // write file version
 330         os.writeShort(BINARY_CSS_VERSION);
 331 


 291      * @param source is the JavaFX .css file to convert
 292      * @param destination is the file to which the binary conversion is written
 293      * @throws IOException
 294      * @throws IllegalArgumentException if either parameter is null, if source and destination are the same,
 295      * if source cannot be read, or if destination cannot be written.
 296      */
 297     public static void convertToBinary(File source, File destination) throws IOException {
 298 
 299         if (source == null || destination == null) {
 300             throw new IllegalArgumentException("parameters may not be null");
 301         }
 302 
 303         if (source.getAbsolutePath().equals(destination.getAbsolutePath())) {
 304             throw new IllegalArgumentException("source and destination may not be the same");
 305         }
 306 
 307         if (source.canRead() == false) {
 308             throw new IllegalArgumentException("cannot read source file");
 309         }
 310 
 311         if (destination.exists() ? (destination.canWrite() == false) : (destination.createNewFile() == false)) {
 312             throw new IllegalArgumentException("cannot write destination file");
 313         }
 314 
 315         URI sourceURI = source.toURI();
 316         Stylesheet stylesheet = CSSParser.getInstance().parse(sourceURI.toURL());
 317 
 318         // first write all the css binary data into the buffer and collect strings on way
 319         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 320         DataOutputStream dos = new DataOutputStream(baos);
 321         StringStore stringStore = new StringStore();
 322         stylesheet.writeBinary(dos, stringStore);
 323         dos.flush();
 324         dos.close();
 325 
 326         FileOutputStream fos = new FileOutputStream(destination);
 327         DataOutputStream os = new DataOutputStream(fos);
 328 
 329         // write file version
 330         os.writeShort(BINARY_CSS_VERSION);
 331