• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java SwiftObjectPath类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: copyThenDeleteObject

import org.apache.hadoop.fs.swift.util.SwiftObjectPath; //导入依赖的package包/类
/**
 * Copy an object then, if the copy worked, delete it.
 * If the copy failed, the source object is not deleted.
 *
 * @param srcObject  source object path
 * @param destObject destination object path
 * @throws IOException IO problems

 */
private void copyThenDeleteObject(SwiftObjectPath srcObject,
                                  SwiftObjectPath destObject) throws
        IOException {


  //do the copy
  copyObject(srcObject, destObject);
  //getting here means the copy worked
  swiftRestClient.delete(srcObject);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:20,代码来源:SwiftNativeFileSystemStore.java


示例17: copyObject

import org.apache.hadoop.fs.swift.util.SwiftObjectPath; //导入依赖的package包/类
/**
 * Copy an object
 * @param srcObject  source object path
 * @param destObject destination object path
 * @throws IOException IO problems
 */
private void copyObject(SwiftObjectPath srcObject,
                                  SwiftObjectPath destObject) throws
        IOException {
  if (srcObject.isEqualToOrParentOf(destObject)) {
    throw new SwiftException(
      "Can't copy " + srcObject + " onto " + destObject);
  }
  //do the copy
  boolean copySucceeded = swiftRestClient.copyObject(srcObject, destObject);
  if (!copySucceeded) {
    throw new SwiftException("Copy of " + srcObject + " to "
            + destObject + "failed");
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:21,代码来源:SwiftNativeFileSystemStore.java


示例18: getCorrectSwiftPath

import org.apache.hadoop.fs.swift.util.SwiftObjectPath; //导入依赖的package包/类
/**
 * Builds a hadoop-Path from a swift path, inserting the URI authority
 * of this FS instance
 * @param path swift object path
 * @return Hadoop path
 * @throws SwiftException if the URI couldn't be created.
 */
private Path getCorrectSwiftPath(SwiftObjectPath path) throws
        SwiftException {
  try {
    final URI fullUri = new URI(uri.getScheme(),
            uri.getAuthority(),
            path.getObject(),
            null,
            null);

    return new Path(fullUri);
  } catch (URISyntaxException e) {
    throw new SwiftException("Specified path " + path + " is incorrect", e);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:22,代码来源:SwiftNativeFileSystemStore.java


示例19: testPutAndDelete

import org.apache.hadoop.fs.swift.util.SwiftObjectPath; //导入依赖的package包/类
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testPutAndDelete() throws Throwable {
  assumeEnabled();
  SwiftRestClient client = createClient();
  client.authenticate();
  Path path = new Path("restTestPutAndDelete");
  SwiftObjectPath sobject = SwiftObjectPath.fromPath(serviceURI, path);
  byte[] stuff = new byte[1];
  stuff[0] = 'a';
  client.upload(sobject, new ByteArrayInputStream(stuff), stuff.length);
  //check file exists
  Duration head = new Duration();
  Header[] responseHeaders = client.headRequest("expect success",
                                                sobject,
                                                SwiftRestClient.NEWEST);
  head.finished();
  LOG.info("head request duration " + head);
  for (Header header: responseHeaders) {
    LOG.info(header.toString());
  }
  //delete the file
  client.delete(sobject);
  //check file is gone
  try {
    Header[] headers = client.headRequest("expect fail",
                                          sobject,
                                          SwiftRestClient.NEWEST);
    Assert.fail("Expected deleted file, but object is still present: "
                + sobject);
  } catch (FileNotFoundException e) {
    //expected
  }
  for (DurationStats stats: client.getOperationStatistics()) {
    LOG.info(stats);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:37,代码来源:TestSwiftRestClient.java


示例20: testParsePath

import org.apache.hadoop.fs.swift.util.SwiftObjectPath; //导入依赖的package包/类
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testParsePath() throws Exception {
  final String pathString = "/home/user/files/file1";
  final Path path = new Path(pathString);
  final URI uri = new URI("http://container.localhost");
  final SwiftObjectPath expected = SwiftObjectPath.fromPath(uri, path);
  final SwiftObjectPath actual = new SwiftObjectPath(
          RestClientBindings.extractContainerName(uri),
          pathString);

  assertEquals(expected, actual);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:13,代码来源:TestSwiftObjectPath.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Resample类代码示例发布时间:2022-05-23
下一篇:
Java CompilerDirectives类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap