File tree Expand file tree Collapse file tree
org/w3c/epubcheck/util/url Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33import java .io .File ;
44import java .io .IOException ;
55import java .io .InputStream ;
6- import java .net .URISyntaxException ;
76import java .nio .charset .StandardCharsets ;
87import java .security .MessageDigest ;
98import java .util .Enumeration ;
1312import java .util .zip .ZipEntry ;
1413import java .util .zip .ZipFile ;
1514
15+ import org .w3c .epubcheck .util .url .URLUtils ;
16+
1617import com .adobe .epubcheck .util .FeatureEnum ;
1718import com .google .common .base .Preconditions ;
1819import com .google .common .collect .ImmutableMap ;
@@ -25,14 +26,7 @@ public class OCFZipResources implements Iterable<OCFResource>
2526
2627 public OCFZipResources (URL url ) throws IOException
2728 {
28- File file = null ;
29- try
30- {
31- file = new File (url .toJavaURI ());
32- } catch (URISyntaxException e )
33- {
34- new IllegalArgumentException ("Not a file URL: " + url );
35- }
29+ File file = URLUtils .toFile (url );
3630 this .zip = new ZipFile (file , StandardCharsets .UTF_8 );
3731 }
3832
Original file line number Diff line number Diff line change 11package com .adobe .epubcheck .opf ;
22
3- import java .io .File ;
4- import java .net .URISyntaxException ;
53import java .util .Arrays ;
64import java .util .EnumSet ;
75import java .util .Locale ;
@@ -163,13 +161,7 @@ private String computePath()
163161 }
164162 else if ("file" .equals (url .scheme ()))
165163 {
166- try
167- {
168- return new File (url .toJavaURI ()).getAbsolutePath ();
169- } catch (URISyntaxException e )
170- {
171- return url .toHumanString ();
172- }
164+ return URLUtils .toFilePath (url );
173165 }
174166 else
175167 {
Original file line number Diff line number Diff line change 66import static io .mola .galimatias .URLUtils .percentEncode ;
77
88import java .io .File ;
9+ import java .net .URISyntaxException ;
10+ import java .nio .file .Paths ;
911import java .text .CharacterIterator ;
1012import java .text .StringCharacterIterator ;
1113
@@ -24,6 +26,26 @@ public static URL toURL(File file)
2426 Preconditions .checkArgument (file != null , "file must not be null" );
2527 return URL .fromJavaURI (file .toURI ());
2628 }
29+
30+ public static File toFile (URL url ) {
31+ Preconditions .checkArgument (url != null , "file must not be null" );
32+ Preconditions .checkArgument ("file" .equals (url .scheme ()));
33+ try {
34+ return Paths .get (url .toJavaURI ()).toFile ();
35+ } catch (URISyntaxException e ) {
36+ throw new IllegalArgumentException (e );
37+ }
38+ }
39+
40+ public static String toFilePath (URL url ) {
41+ Preconditions .checkArgument (url != null , "file must not be null" );
42+ Preconditions .checkArgument ("file" .equals (url .scheme ()));
43+ try {
44+ return Paths .get (url .toJavaURI ()).toString ();
45+ } catch (Exception e ) {
46+ return decode (url .path ());
47+ }
48+ }
2749
2850 public static URL docURL (URL url )
2951 {
You can’t perform that action at this time.
0 commit comments