< prev index next >

test/jaxp/javax/xml/jaxp/libs/jaxp/library/JAXPTestUtilities.java

Print this page
rev 52699 : 8214014: Remove vestiges of gopher: protocol proxy support


 254 
 255         byte[] content = Files.readAllLines(Paths.get(file)).stream().
 256                 collect(Collectors.joining()).getBytes(localCharset);
 257         byte[] head = bom.get(localCharset);
 258         ByteBuffer bb = ByteBuffer.allocate(content.length + head.length);
 259         bb.put(head);
 260         bb.put(content);
 261         return new ByteArrayInputStream(bb.array());
 262     }
 263 
 264    /**
 265      * Worker method to detect common absolute URLs.
 266      *
 267      * @param s String path\filename or URL (or any, really)
 268      * @return true if s starts with a common URI scheme (namely
 269      * the ones found in the examples of RFC2396); false otherwise
 270      */
 271     protected static boolean isCommonURL(String s) {
 272         if (null == s)
 273             return false;
 274         return Pattern.compile("^(file:|http:|ftp:|gopher:|mailto:|news:|telnet:)")
 275                 .matcher(s).matches();
 276     }
 277 
 278     /**
 279      * Utility method to translate a String filename to URL.
 280      *
 281      * If the name starts with a common URI scheme (namely the ones
 282      * found in the examples of RFC2396), then simply return the
 283      * name as-is (the assumption is that it's already a URL).
 284      * Otherwise we attempt (cheaply) to convert to a file:/ URL.
 285      *
 286      * @param filename local path/filename of a file.
 287      * @return a file:/ URL if filename represent a file, the same string if
 288      *         it appears to already be a URL.
 289      */
 290     public static String filenameToURL(String filename) {
 291         return Paths.get(filename).toUri().toASCIIString();
 292     }
 293 
 294     /**




 254 
 255         byte[] content = Files.readAllLines(Paths.get(file)).stream().
 256                 collect(Collectors.joining()).getBytes(localCharset);
 257         byte[] head = bom.get(localCharset);
 258         ByteBuffer bb = ByteBuffer.allocate(content.length + head.length);
 259         bb.put(head);
 260         bb.put(content);
 261         return new ByteArrayInputStream(bb.array());
 262     }
 263 
 264    /**
 265      * Worker method to detect common absolute URLs.
 266      *
 267      * @param s String path\filename or URL (or any, really)
 268      * @return true if s starts with a common URI scheme (namely
 269      * the ones found in the examples of RFC2396); false otherwise
 270      */
 271     protected static boolean isCommonURL(String s) {
 272         if (null == s)
 273             return false;
 274         return Pattern.compile("^(file:|http:|ftp:|mailto:|news:|telnet:)")
 275                 .matcher(s).matches();
 276     }
 277 
 278     /**
 279      * Utility method to translate a String filename to URL.
 280      *
 281      * If the name starts with a common URI scheme (namely the ones
 282      * found in the examples of RFC2396), then simply return the
 283      * name as-is (the assumption is that it's already a URL).
 284      * Otherwise we attempt (cheaply) to convert to a file:/ URL.
 285      *
 286      * @param filename local path/filename of a file.
 287      * @return a file:/ URL if filename represent a file, the same string if
 288      *         it appears to already be a URL.
 289      */
 290     public static String filenameToURL(String filename) {
 291         return Paths.get(filename).toUri().toASCIIString();
 292     }
 293 
 294     /**


< prev index next >