2121import java .io .FileNotFoundException ;
2222import java .io .IOException ;
2323import java .net .URI ;
24- import java .net .URISyntaxException ;
2524import java .util .ArrayList ;
2625import java .util .Arrays ;
2726import java .util .EnumSet ;
@@ -109,15 +108,7 @@ public static FileSystem get(Configuration conf) throws IOException {
109108 * @return the uri of the default filesystem
110109 */
111110 public static URI getDefaultUri (Configuration conf ) {
112- try {
113- String uri = conf .get (FS_DEFAULT_NAME_KEY , null );
114- checkName (uri );
115- return new URI (uri );
116- } catch (Exception e ) {
117- // fs.default.name not set, or set to an invalid value. Create
118- // one based on a known-good URI
119- return URI .create (DEFAULT_FS );
120- }
111+ return URI .create (fixName (conf .get (FS_DEFAULT_NAME_KEY , DEFAULT_FS )));
121112 }
122113
123114 /** Set the default filesystem URI in a configuration.
@@ -131,12 +122,9 @@ public static void setDefaultUri(Configuration conf, URI uri) {
131122 /** Set the default filesystem URI in a configuration.
132123 * @param conf the configuration to alter
133124 * @param uri the new default filesystem uri
134- * @throws IOException if the URI is invalid.
135125 */
136- public static void setDefaultUri (Configuration conf , String uri )
137- throws IOException {
138- checkName (uri );
139- setDefaultUri (conf , URI .create (uri ));
126+ public static void setDefaultUri (Configuration conf , String uri ) {
127+ setDefaultUri (conf , URI .create (fixName (uri )));
140128 }
141129
142130 /** Called after a new FileSystem instance is constructed.
@@ -150,52 +138,22 @@ public void initialize(URI name, Configuration conf) throws IOException {
150138
151139 /** Returns a URI whose scheme and authority identify this FileSystem.*/
152140 public abstract URI getUri ();
153-
154- /** Checks that a FileSystem name is given in an understandable format.
155- * The old "local" alias for "file:///" is unsupported, as are any
156- * URIs without a scheme component.
157- * @throws IOException if a name is in an unsupported format
158- */
159- private static void checkName (String name ) throws IOException {
160- if (null == name ) {
161- throw new IOException ("Null FS name provided to checkName()" );
162- } else if ("local" .equals (name )) {
163- throw new IOException ("FileSystem 'local' is not supported; use 'file:///'" );
164- } else {
165- // Try parsing this into a URI
166- try {
167- URI uri = new URI (name );
168-
169- // No scheme; don't know how to parse this.
170- if (null == uri .getScheme ()) {
171- throw new IOException ("FileSystem name '" + name
172- + "' is provided in an unsupported format. (Try 'hdfs://"
173- + name + "' instead?)" );
174- }
175-
176- // This may have been a misparse. java.net.URI specifies that
177- // a URI is of the form:
178- // URI ::= [SCHEME-PART:]SCHEME-SPECIFIC-PART
179- //
180- // The scheme-specific-part may be parsed in numerous ways, but if
181- // it starts with a '/' character, that makes it a "hierarchical URI",
182- // subject to the following parsing:
183- // SCHEME-SPECIFIC-PART ::= "//" AUTHORITY-PART
184- // AUTHORITY-PART ::= [USER-INFO-PART] HOSTNAME [ ":" PORT ]
185- //
186- // In Hadoop, we require a host-based authority as well.
187- // java.net.URI parses left-to-right, so deprecated hostnames of the
188- // form 'foo:8020' will have 'foo' as their scheme and '8020' as their
189- // scheme-specific-part. We don't want this behavior.
190- if (null == uri .getAuthority ()) {
191- throw new IOException ("FileSystem name '" + name
192- + "' is provided in an unsupported format. (Try 'hdfs://"
193- + name + "' instead?)" );
194- }
195- } catch (URISyntaxException use ) {
196- throw new IOException ("FileSystem name cannot be understood as a URI" , use );
197- }
198- }
141+
142+ /** Update old-format filesystem names, for back-compatibility. This should
143+ * eventually be replaced with a checkName() method that throws an exception
144+ * for old-format names. */
145+ private static String fixName (String name ) {
146+ // convert old-format name to new-format name
147+ if (name .equals ("local" )) { // "local" is now "file:///".
148+ LOG .warn ("\" local\" is a deprecated filesystem name."
149+ +" Use \" file:///\" instead." );
150+ name = "file:///" ;
151+ } else if (name .indexOf ('/' )==-1 ) { // unqualified is "hdfs://"
152+ LOG .warn ("\" " +name +"\" is a deprecated filesystem name."
153+ +" Use \" hdfs://" +name +"/\" instead." );
154+ name = "hdfs://" +name ;
155+ }
156+ return name ;
199157 }
200158
201159 /**
0 commit comments