当前位置: 首页>>代码示例>>Java>>正文


Java SwiftObjectPath类代码示例

本文整理汇总了Java中org.apache.hadoop.fs.swift.util.SwiftObjectPath的典型用法代码示例。如果您正苦于以下问题:Java SwiftObjectPath类的具体用法?Java SwiftObjectPath怎么用?Java SwiftObjectPath使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SwiftObjectPath类属于org.apache.hadoop.fs.swift.util包,在下文中一共展示了SwiftObjectPath类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: uploadFilePart

import org.apache.hadoop.fs.swift.util.SwiftObjectPath; //导入依赖的package包/类
/**
 * Upload part of a larger file.
 *
 * @param path        destination path
 * @param partNumber  item number in the path
 * @param inputStream input data
 * @param length      length of the data
 * @throws IOException on a problem
 */
public void uploadFilePart(Path path, int partNumber,
                           InputStream inputStream, long length)
        throws IOException {

  String stringPath = path.toUri().toString();
  String partitionFilename = SwiftUtils.partitionFilenameFromNumber(
    partNumber);
  if (stringPath.endsWith("/")) {
    stringPath = stringPath.concat(partitionFilename);
  } else {
    stringPath = stringPath.concat("/").concat(partitionFilename);
  }

  swiftRestClient.upload(
    new SwiftObjectPath(toDirPath(path).getContainer(), stringPath),
          inputStream,
          length);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:28,代码来源:SwiftNativeFileSystemStore.java

示例2: testChildOfProbe

import org.apache.hadoop.fs.swift.util.SwiftObjectPath; //导入依赖的package包/类
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testChildOfProbe() throws Throwable {
  SwiftObjectPath parent = new SwiftObjectPath("container",
                                               "/parent");
  SwiftObjectPath parent2 = new SwiftObjectPath("container",
                                               "/parent2");
  SwiftObjectPath child = new SwiftObjectPath("container",
                                               "/parent/child");
  SwiftObjectPath sibling = new SwiftObjectPath("container",
                                               "/parent/sibling");
  SwiftObjectPath grandchild = new SwiftObjectPath("container",
                                                   "/parent/child/grandchild");
  assertParentOf(parent, child);
  assertParentOf(parent, grandchild);
  assertParentOf(child, grandchild);
  assertParentOf(parent, parent);
  assertNotParentOf(child, parent);
  assertParentOf(child, child);
  assertNotParentOf(parent, parent2);
  assertNotParentOf(grandchild, parent);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:22,代码来源:TestSwiftObjectPath.java

示例3: pathToObjectLocation

import org.apache.hadoop.fs.swift.util.SwiftObjectPath; //导入依赖的package包/类
/**
 * Create the URI needed to query the location of an object
 * @param path object path to retrieve information about
 * @return the URI for the location operation
 * @throws SwiftException if the URI could not be constructed
 */
private URI pathToObjectLocation(SwiftObjectPath path) throws SwiftException {
  URI uri;
  String dataLocationURI = objectLocationURI.toString();
  try {
    if (path.toString().startsWith("/")) {
      dataLocationURI = dataLocationURI.concat(path.toUriPath());
    } else {
      dataLocationURI = dataLocationURI.concat("/").concat(path.toUriPath());
    }

    uri = new URI(dataLocationURI);
  } catch (URISyntaxException e) {
    throw new SwiftException(e);
  }
  return uri;
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:23,代码来源:SwiftRestClient.java

示例4: uploadFilePart

import org.apache.hadoop.fs.swift.util.SwiftObjectPath; //导入依赖的package包/类
/**
 * Upload part of a larger file.
 *
 * @param path        destination path
 * @param partNumber  item number in the path
 * @param inputStream input data
 * @param length      length of the data
 * @throws IOException on a problem
 */
public void uploadFilePart(Path path, int partNumber,
                           InputStream inputStream, long length)
        throws IOException {

  String stringPath = path.toUri().getPath();
  String partitionFilename = SwiftUtils.partitionFilenameFromNumber(
    partNumber);
  if (stringPath.endsWith("/")) {
    stringPath = stringPath.concat(partitionFilename);
  } else {
    stringPath = stringPath.concat("/").concat(partitionFilename);
  }

  swiftRestClient.upload(
    new SwiftObjectPath(toDirPath(path).getContainer(), stringPath),
          inputStream,
          length);
}
 
开发者ID:openstack,项目名称:sahara-extra,代码行数:28,代码来源:SwiftNativeFileSystemStore.java

示例5: deleteObject

import org.apache.hadoop.fs.swift.util.SwiftObjectPath; //导入依赖的package包/类
/**
 * deletes object from Swift
 *
 * @param status FileStatus to delete
 * @return true if the path was deleted by this specific operation.
 * @throws IOException on a failure
 */
public boolean deleteObject(FileStatus status) throws IOException {
  SwiftObjectPath swiftObjectPath;
  if (status.isDir()) {
    swiftObjectPath = toDirPath(status.getPath());
  } else {
    swiftObjectPath = toObjectPath(status.getPath());
  }
  if (!SwiftUtils.isRootDir(swiftObjectPath)) {
    return swiftRestClient.delete(swiftObjectPath);
  } else {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Not deleting root directory entry");
    }
    return true;
  }
}
 
开发者ID:openstack,项目名称:sahara-extra,代码行数:24,代码来源:SwiftNativeFileSystemStore.java

示例6: listSegments

import org.apache.hadoop.fs.swift.util.SwiftObjectPath; //导入依赖的package包/类
/**
 * List all segments in dynamic large object.
 *
 * @param file   SwiftFileStatus of large object
 * @param newest ask for the newest, or can some out of date data work?
 * @return the file statuses, or an empty array if there are no segments
 * @throws IOException           on IO problems
 */
public FileStatus[] listSegments(FileStatus file, boolean newest)
    throws IOException {
  SwiftObjectPath prefix = ((SwiftFileStatus)file).getDLOPrefix();
  if (prefix == null) {
    return new FileStatus[0];
  }

  final List<FileStatus> objects;
  objects = listDirectory(prefix, true, newest, false);

  final ArrayList<FileStatus> segments;
  segments = new ArrayList<FileStatus>(objects.size());

  for (FileStatus status : objects) {
    if (!status.isDir()) {
      segments.add(status);
    }
  }

  return segments.toArray(new FileStatus[segments.size()]);
}
 
开发者ID:openstack,项目名称:sahara-extra,代码行数:30,代码来源:SwiftNativeFileSystemStore.java

示例7: getRawObjectNames

import org.apache.hadoop.fs.swift.util.SwiftObjectPath; //导入依赖的package包/类
private String[] getRawObjectNames() throws Exception {
  SwiftRestClient client;
  client = SwiftRestClient.getInstance(fs.getUri(), fs.getConf());
  SwiftObjectPath path = SwiftObjectPath.fromPath(fs.getUri(), new Path("/"));
  byte[] bytes = client.listDeepObjectsInDirectory(path, true, true);
  final CollectionType collectionType = JSONUtil.getJsonMapper().
    getTypeFactory().constructCollectionType(List.class,
                                             SwiftObjectFileStatus.class);
  final List<SwiftObjectFileStatus> fileStatusList =
    JSONUtil.toObject(new String(bytes), collectionType);
  final ArrayList<String> objects = new ArrayList();
  for (SwiftObjectFileStatus status : fileStatusList) {
    if (status.getName() != null) {
      objects.add(status.getName());
    } else if (status.getSubdir() != null) {
      objects.add(status.getSubdir());
    }
  }
  return objects.toArray(new String[objects.size()]);
}
 
开发者ID:openstack,项目名称:sahara-extra,代码行数:21,代码来源:TestSwiftFileSystemDirectories.java

示例8: getData

import org.apache.hadoop.fs.swift.util.SwiftObjectPath; //导入依赖的package包/类
/**
 * Make an HTTP GET request to Swift to get a range of data in the object.
 *
 * @param path   path to object
 * @param offset offset from file beginning
 * @param length file length
 * @return The input stream -which must be closed afterwards.
 * @throws IOException Problems
 * @throws SwiftException swift specific error
 * @throws FileNotFoundException path is not there
 */
public HttpBodyContent getData(SwiftObjectPath path,
                               long offset,
                               long length) throws IOException {
  if (offset < 0) {
    throw new SwiftException("Invalid offset: " + offset
                          + " in getDataAsInputStream( path=" + path
                          + ", offset=" + offset
                          + ", length =" + length + ")");
  }
  if (length <= 0) {
    throw new SwiftException("Invalid length: " + length
              + " in getDataAsInputStream( path="+ path
                          + ", offset=" + offset
                          + ", length ="+ length + ")");
  }

  final String range = String.format(SWIFT_RANGE_HEADER_FORMAT_PATTERN,
          offset,
          offset + length - 1);
  if (LOG.isDebugEnabled()) {
    LOG.debug("getData:" + range);
  }

  return getData(path,
                 new Header(HEADER_RANGE, range),
                 SwiftRestClient.NEWEST);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:39,代码来源:SwiftRestClient.java

示例9: listDeepObjectsInDirectory

import org.apache.hadoop.fs.swift.util.SwiftObjectPath; //导入依赖的package包/类
/**
 * Find objects in a directory
 *
 * @param path path prefix
 * @param requestHeaders optional request headers
 * @return byte[] file data or null if the object was not found
 * @throws IOException on IO Faults
 * @throws FileNotFoundException if nothing is at the end of the URI -that is,
 * the directory is empty
 */
public byte[] listDeepObjectsInDirectory(SwiftObjectPath path,
                                         boolean listDeep,
                                     final Header... requestHeaders)
        throws IOException {
  preRemoteCommand("listDeepObjectsInDirectory");

  String endpoint = getEndpointURI().toString();
  StringBuilder dataLocationURI = new StringBuilder();
  dataLocationURI.append(endpoint);
  String object = path.getObject();
  if (object.startsWith("/")) {
    object = object.substring(1);
  }
  if (!object.endsWith("/")) {
    object = object.concat("/");
  }

  if (object.equals("/")) {
    object = "";
  }

  dataLocationURI = dataLocationURI.append("/")
          .append(path.getContainer())
          .append("/?prefix=")
          .append(object)
          .append("&format=json");

  //in listing deep set param to false
  if (listDeep == false) {
      dataLocationURI.append("&delimiter=/");
  }

  return findObjects(dataLocationURI.toString(), requestHeaders);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:45,代码来源:SwiftRestClient.java

示例10: createContainer

import org.apache.hadoop.fs.swift.util.SwiftObjectPath; //导入依赖的package包/类
/**
 * Create a container -if it already exists, do nothing
 *
 * @param containerName the container name
 * @throws IOException IO problems
 * @throws SwiftBadRequestException invalid container name
 * @throws SwiftInvalidResponseException error from the server
 */
public void createContainer(String containerName) throws IOException {
  SwiftObjectPath objectPath = new SwiftObjectPath(containerName, "");
  try {
    //see if the data is there
    headRequest("createContainer", objectPath, NEWEST);
  } catch (FileNotFoundException ex) {
    int status = 0;
    try {
      status = putRequest(objectPath);
    } catch (FileNotFoundException e) {
      //triggered by a very bad container name.
      //re-insert the 404 result into the status
      status = SC_NOT_FOUND;
    }
    if (status == SC_BAD_REQUEST) {
      throw new SwiftBadRequestException(
        "Bad request -authentication failure or bad container name?",
        status,
        "PUT",
        null);
    }
    if (!isStatusCodeExpected(status,
            SC_OK,
            SC_CREATED,
            SC_ACCEPTED,
            SC_NO_CONTENT)) {
      throw new SwiftInvalidResponseException("Couldn't create container "
              + containerName +
              " for storing data in Swift." +
              " Try to create container " +
              containerName + " manually ",
              status,
              "PUT",
              null);
    } else {
      throw ex;
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:48,代码来源:SwiftRestClient.java

示例11: pathToURI

import org.apache.hadoop.fs.swift.util.SwiftObjectPath; //导入依赖的package包/类
/**
 * Converts Swift path to URI to make request.
 * This is public for unit testing
 *
 * @param path path to object
 * @param endpointURI damain url e.g. http://domain.com
 * @return valid URI for object
 * @throws SwiftException
 */
public static URI pathToURI(SwiftObjectPath path,
                            URI endpointURI) throws SwiftException {
  checkNotNull(endpointURI, "Null Endpoint -client is not authenticated");

  String dataLocationURI = endpointURI.toString();
  try {

    dataLocationURI = SwiftUtils.joinPaths(dataLocationURI, encodeUrl(path.toUriPath()));
    return new URI(dataLocationURI);
  } catch (URISyntaxException e) {
    throw new SwiftException("Failed to create URI from " + dataLocationURI, e);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:23,代码来源:SwiftRestClient.java

示例12: stat

import org.apache.hadoop.fs.swift.util.SwiftObjectPath; //导入依赖的package包/类
private Header[] stat(SwiftObjectPath objectPath, boolean newest) throws
                                                                  IOException {
  Header[] headers;
  if (newest) {
    headers = swiftRestClient.headRequest("getObjectMetadata-newest",
                                          objectPath, SwiftRestClient.NEWEST);
  } else {
    headers = swiftRestClient.headRequest("getObjectMetadata",
                                          objectPath);
  }
  return headers;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:13,代码来源:SwiftNativeFileSystemStore.java

示例13: deleteObject

import org.apache.hadoop.fs.swift.util.SwiftObjectPath; //导入依赖的package包/类
/**
 * deletes object from Swift
 *
 * @param path path to delete
 * @return true if the path was deleted by this specific operation.
 * @throws IOException on a failure
 */
public boolean deleteObject(Path path) throws IOException {
  SwiftObjectPath swiftObjectPath = toObjectPath(path);
  if (!SwiftUtils.isRootDir(swiftObjectPath)) {
    return swiftRestClient.delete(swiftObjectPath);
  } else {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Not deleting root directory entry");
    }
    return true;
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:19,代码来源:SwiftNativeFileSystemStore.java

示例14: objectExists

import org.apache.hadoop.fs.swift.util.SwiftObjectPath; //导入依赖的package包/类
/**
 * Does the object exist
 *
 * @param path swift object path
 * @return true if the metadata of an object could be retrieved
 * @throws IOException IO problems other than FileNotFound, which
 *                     is downgraded to an object does not exist return code
 */
public boolean objectExists(SwiftObjectPath path) throws IOException {
  try {
    Header[] headers = swiftRestClient.headRequest("objectExists",
                                                   path,
                                                   SwiftRestClient.NEWEST);
    //no headers is treated as a missing file
    return headers.length != 0;
  } catch (FileNotFoundException e) {
    return false;
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:20,代码来源:SwiftNativeFileSystemStore.java

示例15: logDirectory

import org.apache.hadoop.fs.swift.util.SwiftObjectPath; //导入依赖的package包/类
/**
 * Debug action to dump directory statuses to the debug log
 *
 * @param message    explanation
 * @param objectPath object path (can be null)
 * @param statuses   listing output
 */
private void logDirectory(String message, SwiftObjectPath objectPath,
                          Iterable<FileStatus> statuses) {

  if (LOG.isDebugEnabled()) {
    LOG.debug(message + ": listing of " + objectPath);
    for (FileStatus fileStatus : statuses) {
      LOG.debug(fileStatus.getPath());
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:18,代码来源:SwiftNativeFileSystemStore.java


注:本文中的org.apache.hadoop.fs.swift.util.SwiftObjectPath类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。