Java Code Examples for org.apache.commons.httpclient.util.URIUtil#encodePath()

The following examples show how to use org.apache.commons.httpclient.util.URIUtil#encodePath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MockStorageInterface.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public CloudBlobContainerWrapper getContainerReference(String name)
    throws URISyntaxException, StorageException {
  String fullUri;
  try {
    fullUri = baseUriString + "/" + URIUtil.encodePath(name);
  } catch (URIException e) {
    throw new RuntimeException("problem encoding fullUri", e);
  }

  MockCloudBlobContainerWrapper container = new MockCloudBlobContainerWrapper(
      fullUri, name);
  // Check if we have a pre-existing container with that name, and prime
  // the wrapper with that knowledge if it's found.
  for (PreExistingContainer existing : preExistingContainers) {
    if (fullUri.equalsIgnoreCase(existing.containerUri)) {
      // We have a pre-existing container. Mark the wrapper as created and
      // make sure we use the metadata for it.
      container.created = true;
      backingStore.setContainerMetadata(existing.containerMetadata);
      break;
    }
  }
  return container;
}
 
Example 2
Source File: MockStorageInterface.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private String fullUriString(String relativePath, boolean withTrailingSlash) {
  String fullUri;

  String baseUri = this.baseUri;
  if (!baseUri.endsWith("/")) {
    baseUri += "/";
  }
  if (withTrailingSlash && !relativePath.equals("")
      && !relativePath.endsWith("/")) {
    relativePath += "/";
  }

  try {
    fullUri = baseUri + URIUtil.encodePath(relativePath);
  } catch (URIException e) {
    throw new RuntimeException("problem encoding fullUri", e);
  }

  return fullUri;
}
 
Example 3
Source File: MockStorageInterface.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
public CloudBlobContainerWrapper getContainerReference(String name)
    throws URISyntaxException, StorageException {
  String fullUri;
  try {
    fullUri = baseUriString + "/" + URIUtil.encodePath(name);
  } catch (URIException e) {
    throw new RuntimeException("problem encoding fullUri", e);
  }

  MockCloudBlobContainerWrapper container = new MockCloudBlobContainerWrapper(
      fullUri, name);
  // Check if we have a pre-existing container with that name, and prime
  // the wrapper with that knowledge if it's found.
  for (PreExistingContainer existing : preExistingContainers) {
    if (fullUri.equalsIgnoreCase(existing.containerUri)) {
      // We have a pre-existing container. Mark the wrapper as created and
      // make sure we use the metadata for it.
      container.created = true;
      backingStore.setContainerMetadata(existing.containerMetadata);
      break;
    }
  }
  return container;
}
 
Example 4
Source File: MockStorageInterface.java    From big-c with Apache License 2.0 6 votes vote down vote up
private String fullUriString(String relativePath, boolean withTrailingSlash) {
  String fullUri;

  String baseUri = this.baseUri;
  if (!baseUri.endsWith("/")) {
    baseUri += "/";
  }
  if (withTrailingSlash && !relativePath.equals("")
      && !relativePath.endsWith("/")) {
    relativePath += "/";
  }

  try {
    fullUri = baseUri + URIUtil.encodePath(relativePath);
  } catch (URIException e) {
    throw new RuntimeException("problem encoding fullUri", e);
  }

  return fullUri;
}
 
Example 5
Source File: URLFileName.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the path encoded suitable for url like file system e.g. (http, webdav).
 *
 * @param charset the charset used for the path encoding
 * @return The encoded path.
 * @throws URIException If an error occurs encoding the URI.
 * @throws FileSystemException If some other error occurs.
 */
public String getPathQueryEncoded(final String charset) throws URIException, FileSystemException {
    if (getQueryString() == null) {
        if (charset != null) {
            return URIUtil.encodePath(getPathDecoded(), charset);
        }
        return URIUtil.encodePath(getPathDecoded());
    }

    final StringBuilder sb = new StringBuilder(BUFFER_SIZE);
    if (charset != null) {
        sb.append(URIUtil.encodePath(getPathDecoded(), charset));
    } else {
        sb.append(URIUtil.encodePath(getPathDecoded()));
    }
    sb.append("?");
    sb.append(getQueryString());
    return sb.toString();
}
 
Example 6
Source File: ServletUtil.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Escape and encode a string regarded as the path component of an URI.
 * @param path the path component to encode
 * @return encoded path, null if UTF-8 is not supported
 */
public static String encodePath(final String path) {
  try {
    return URIUtil.encodePath(path, "UTF-8");
  } catch (URIException e) {
    throw new AssertionError("JVM does not support UTF-8"); // should never happen!
  }
}
 
Example 7
Source File: ServletUtil.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Escape and encode a string regarded as the path component of an URI.
 * @param path the path component to encode
 * @return encoded path, null if UTF-8 is not supported
 */
public static String encodePath(final String path) {
  try {
    return URIUtil.encodePath(path, "UTF-8");
  } catch (URIException e) {
    throw new AssertionError("JVM does not support UTF-8"); // should never happen!
  }
}
 
Example 8
Source File: HttpEncodingTools.java    From elasticsearch-hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Encodes characters in the string except for those allowed in an absolute path.
 *
 * @deprecated Prefer to use {@link HttpEncodingTools#encode(String)} instead for encoding specific
 * pieces of the URI. This method does not escape certain reserved characters, like '/' and ':'.
 * As such, this is not safe to use on paths that may contain these reserved characters in the wrong places.
 */
@Deprecated
public static String encodePath(String path) {
    try {
        return URIUtil.encodePath(path, "UTF-8");
    } catch (URIException ex) {
        throw new EsHadoopIllegalArgumentException("Cannot encode path segment [" + path + "]", ex);
    }
}
 
Example 9
Source File: HttpFileObject.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
protected String encodePath(final String decodedPath) throws URIException {
    return URIUtil.encodePath(decodedPath);
}