List of usage examples for java.net MalformedURLException MalformedURLException
public MalformedURLException(String msg)
From source file:com.remobile.file.FileUtils.java
/** * Deletes a file or directory. It is an error to attempt to delete a directory that is not empty. * It is an error to attempt to delete the root directory of a filesystem. * * @return a boolean representing success of failure * @throws NoModificationAllowedException * @throws InvalidModificationException/*from w w w . j ava 2 s. c o m*/ * @throws MalformedURLException */ private boolean remove(String baseURLstr) throws NoModificationAllowedException, InvalidModificationException, MalformedURLException { try { LocalFilesystemURL inputURL = LocalFilesystemURL.parse(baseURLstr); // You can't delete the root directory. if ("".equals(inputURL.path) || "/".equals(inputURL.path)) { throw new NoModificationAllowedException("You can't delete the root directory"); } Filesystem fs = this.filesystemForURL(inputURL); if (fs == null) { throw new MalformedURLException("No installed handlers for this URL"); } return fs.removeFileAtLocalURL(inputURL); } catch (IllegalArgumentException e) { throw new MalformedURLException("Unrecognized filesystem URL"); } }
From source file:net.yacy.cora.document.id.MultiProtocolURL.java
private void identPort(final String inputURL, final int dflt) throws MalformedURLException { // identify ref in file if (this.host == null) { this.port = dflt; return;// w w w. ja v a 2 s .co m } int pss = 0; int ip6 = this.host.indexOf('['); if (ip6 >= 0 && ((ip6 = this.host.indexOf("]", ip6)) > 0)) { pss = ip6 + 1; } final int r = this.host.indexOf(":", pss); if (r < 0) { this.port = dflt; } else { try { final String portStr = this.host.substring(r + 1); if (portStr.trim().length() > 0) this.port = Integer.parseInt(portStr); else this.port = dflt; this.host = this.host.substring(0, r); } catch (final NumberFormatException e) { throw new MalformedURLException( "wrong port in host fragment '" + this.host + "' of input url '" + inputURL + "'"); } } }
From source file:com.remobile.file.FileUtils.java
/** * Creates or looks up a file./*from w w w . j a va2 s .c o m*/ * * @param baseURLstr base directory * @param path file/directory to lookup or create * @param options specify whether to create or not * @param directory if true look up directory, if false look up file * @return a Entry object * @throws FileExistsException * @throws IOException * @throws TypeMismatchException * @throws EncodingException * @throws JSONException */ private JSONObject getFile(String baseURLstr, String path, JSONObject options, boolean directory) throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException { try { LocalFilesystemURL inputURL = LocalFilesystemURL.parse(baseURLstr); Filesystem fs = this.filesystemForURL(inputURL); if (fs == null) { throw new MalformedURLException("No installed handlers for this URL"); } return fs.getFileForLocalURL(inputURL, path, options, directory); } catch (IllegalArgumentException e) { throw new MalformedURLException("Unrecognized filesystem URL"); } }
From source file:com.remobile.file.FileUtils.java
/** * Look up the parent DirectoryEntry containing this Entry. * If this Entry is the root of its filesystem, its parent is itself. *///ww w . j ava 2 s . co m private JSONObject getParent(String baseURLstr) throws JSONException, IOException { try { LocalFilesystemURL inputURL = LocalFilesystemURL.parse(baseURLstr); Filesystem fs = this.filesystemForURL(inputURL); if (fs == null) { throw new MalformedURLException("No installed handlers for this URL"); } return fs.getParentForLocalURL(inputURL); } catch (IllegalArgumentException e) { throw new MalformedURLException("Unrecognized filesystem URL"); } }
From source file:com.remobile.file.FileUtils.java
/** * Returns a File that represents the current state of the file that this FileEntry represents. * * @return returns a JSONObject represent a W3C File object *///from w w w. j av a 2 s .c o m private JSONObject getFileMetadata(String baseURLstr) throws FileNotFoundException, JSONException, MalformedURLException { try { LocalFilesystemURL inputURL = LocalFilesystemURL.parse(baseURLstr); Filesystem fs = this.filesystemForURL(inputURL); if (fs == null) { throw new MalformedURLException("No installed handlers for this URL"); } return fs.getFileMetadataForLocalURL(inputURL); } catch (IllegalArgumentException e) { throw new MalformedURLException("Unrecognized filesystem URL"); } }
From source file:com.remobile.file.FileUtils.java
/** * Read the contents of a file.//from w w w .j av a2 s . c o m * This is done in a background thread; the result is sent to the callback. * * @param start Start position in the file. * @param end End position to stop at (exclusive). * @param callbackContext The context through which to send the result. * @param encoding The encoding to return contents as. Typical value is UTF-8. (see http://www.iana.org/assignments/character-sets) * @param resultType The desired type of data to send to the callback. * @return Contents of file. */ public void readFileAs(final String srcURLstr, final int start, final int end, final CallbackContext callbackContext, final String encoding, final int resultType) throws MalformedURLException { try { LocalFilesystemURL inputURL = LocalFilesystemURL.parse(srcURLstr); Filesystem fs = this.filesystemForURL(inputURL); if (fs == null) { throw new MalformedURLException("No installed handlers for this URL"); } fs.readFileAtURL(inputURL, start, end, new Filesystem.ReadFileCallback() { public void handleData(InputStream inputStream, String contentType) { try { ByteArrayOutputStream os = new ByteArrayOutputStream(); final int BUFFER_SIZE = 8192; byte[] buffer = new byte[BUFFER_SIZE]; for (;;) { int bytesRead = inputStream.read(buffer, 0, BUFFER_SIZE); if (bytesRead <= 0) { break; } os.write(buffer, 0, bytesRead); } PluginResult result; switch (resultType) { case PluginResult.MESSAGE_TYPE_STRING: result = new PluginResult(PluginResult.Status.OK, os.toString(encoding)); break; case PluginResult.MESSAGE_TYPE_ARRAYBUFFER: result = new PluginResult(PluginResult.Status.OK, os.toByteArray()); break; case PluginResult.MESSAGE_TYPE_BINARYSTRING: result = new PluginResult(PluginResult.Status.OK, os.toByteArray(), true); break; default: // Base64. byte[] base64 = Base64.encode(os.toByteArray(), Base64.NO_WRAP); String s = "data:" + contentType + ";base64," + new String(base64, "US-ASCII"); result = new PluginResult(PluginResult.Status.OK, s); } callbackContext.sendPluginResult(result); } catch (IOException e) { Log.d(LOG_TAG, e.getLocalizedMessage()); callbackContext.sendPluginResult( new PluginResult(PluginResult.Status.IO_EXCEPTION, NOT_READABLE_ERR)); } } }); } catch (IllegalArgumentException e) { throw new MalformedURLException("Unrecognized filesystem URL"); } catch (FileNotFoundException e) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, NOT_FOUND_ERR)); } catch (IOException e) { Log.d(LOG_TAG, e.getLocalizedMessage()); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, NOT_READABLE_ERR)); } }
From source file:com.gargoylesoftware.htmlunit.WebClient.java
/** * Loads a {@link WebResponse} from the server. * @param webRequest the request/*from ww w.j ava 2 s .c o m*/ * @throws IOException if an IO problem occurs * @return the WebResponse */ public WebResponse loadWebResponse(final WebRequest webRequest) throws IOException { final WebResponse response; final String protocol = webRequest.getUrl().getProtocol(); if ("about".equals(protocol)) { response = makeWebResponseForAboutUrl(webRequest.getUrl()); } else if ("file".equals(protocol)) { response = makeWebResponseForFileUrl(webRequest); } else if ("data".equals(protocol)) { if (browserVersion_.hasFeature(PROTOCOL_DATA)) { response = makeWebResponseForDataUrl(webRequest); } else { throw new MalformedURLException("Unknown protocol: data"); } } else { response = loadWebResponseFromWebConnection(webRequest, ALLOWED_REDIRECTIONS_SAME_URL); } return response; }
From source file:com.remobile.file.FileUtils.java
/** * Write contents of file./* w ww .j av a 2s . c o m*/ * * @param data The contents of the file. * @param offset The position to begin writing the file. * @param isBinary True if the file contents are base64-encoded binary data */ /**/ public long write(String srcURLstr, String data, int offset, boolean isBinary) throws FileNotFoundException, IOException, NoModificationAllowedException { try { LocalFilesystemURL inputURL = LocalFilesystemURL.parse(srcURLstr); Filesystem fs = this.filesystemForURL(inputURL); if (fs == null) { throw new MalformedURLException("No installed handlers for this URL"); } long x = fs.writeToFileAtURL(inputURL, data, offset, isBinary); Log.d("TEST", srcURLstr + ": " + x); return x; } catch (IllegalArgumentException e) { throw new MalformedURLException("Unrecognized filesystem URL"); } }
From source file:com.remobile.file.FileUtils.java
/** * Truncate the file to size/*from w w w . jav a2s . c o m*/ */ private long truncateFile(String srcURLstr, long size) throws FileNotFoundException, IOException, NoModificationAllowedException { try { LocalFilesystemURL inputURL = LocalFilesystemURL.parse(srcURLstr); Filesystem fs = this.filesystemForURL(inputURL); if (fs == null) { throw new MalformedURLException("No installed handlers for this URL"); } return fs.truncateFileAtURL(inputURL, size); } catch (IllegalArgumentException e) { throw new MalformedURLException("Unrecognized filesystem URL"); } }