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


Java MantaClientHttpResponseException类代码示例

本文整理汇总了Java中com.joyent.manta.exception.MantaClientHttpResponseException的典型用法代码示例。如果您正苦于以下问题:Java MantaClientHttpResponseException类的具体用法?Java MantaClientHttpResponseException怎么用?Java MantaClientHttpResponseException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getFileStatus

import com.joyent.manta.exception.MantaClientHttpResponseException; //导入依赖的package包/类
@Override
public FileStatus getFileStatus(final Path path) throws IOException {
    String mantaPath = mantaPath(path);
    LOG.debug("Getting path status for: {}", mantaPath);

    if (mantaPath.equals(SEPARATOR)) {
        return MantaFileStatus.ROOT;
    }

    final MantaObjectResponse response;

    try {
        response = client.head(mantaPath);
    } catch (MantaClientHttpResponseException e) {
        if (e.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
            throw new FileNotFoundException(mantaPath);
        }

        throw e;
    }

    MantaFileStatus status = new MantaFileStatus(response, path);

    return status;
}
 
开发者ID:joyent,项目名称:hadoop-manta,代码行数:26,代码来源:MantaFileSystem.java

示例2: getFileChecksum

import com.joyent.manta.exception.MantaClientHttpResponseException; //导入依赖的package包/类
/**
 * Get the checksum of a file.
 *
 * @param file The file path
 * @return The file checksum.  The default return value is null,
 * which indicates that no checksum algorithm is implemented
 * in the corresponding FileSystem.
 */
@Override
public FileChecksum getFileChecksum(final Path file) throws IOException {
    final String mantaPath = mantaPath(file);

    try {
        final MantaObject head = client.head(mantaPath);

        if (head.isDirectory()) {
            throw new IOException("Can't get checksum of directory");
        }

        byte[] md5bytes = head.getMd5Bytes();
        return new MantaChecksum(md5bytes);
    } catch (MantaClientHttpResponseException e) {
        if (e.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
            throw new FileNotFoundException(mantaPath);
        }
        throw e;
    }
}
 
开发者ID:joyent,项目名称:hadoop-manta,代码行数:29,代码来源:MantaFileSystem.java

示例3: setup

import com.joyent.manta.exception.MantaClientHttpResponseException; //导入依赖的package包/类
@BeforeClass
public static void setup() throws IOException {
    fs = instance();
    client = fs.getMantaClient();
    config = fs.getConfig();

    basePath = String.format("%s/stor/%s/",
            config.getMantaHomeDirectory(), UUID.randomUUID());

    try {
        client.putDirectory(basePath);
    } catch (MantaClientHttpResponseException e) {
        if (e.getServerCode().equals(MantaErrorCode.ACCOUNT_BLOCKED_ERROR)) {
            throw new IOException("You must have Manta credentials setup to "
                    + "run the integration test suite", e);
        }
    }
}
 
开发者ID:joyent,项目名称:hadoop-manta,代码行数:19,代码来源:MantaFileSystemIT.java

示例4: map

import com.joyent.manta.exception.MantaClientHttpResponseException; //导入依赖的package包/类
@Override
public BackgroundException map(final MantaClientHttpResponseException failure) {
    switch(failure.getStatusCode()) {
        case 403:
            final StringBuilder buffer = new StringBuilder();
            this.append(buffer, failure.getStatusMessage());
            return new LoginFailureException(buffer.toString(), failure);
    }
    return new HttpResponseExceptionMappingService().map(new HttpResponseException(failure.getStatusCode(), failure.getStatusMessage()));
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:11,代码来源:MantaHttpExceptionMappingService.java

示例5: delete

import com.joyent.manta.exception.MantaClientHttpResponseException; //导入依赖的package包/类
@Override
public boolean delete(final Path path, final boolean recursive) throws IOException {
    String mantaPath = mantaPath(path);

    // We don't bother deleting something that doesn't exist

    final MantaObjectResponse head;

    try {
         head = client.head(mantaPath);
    } catch (MantaClientHttpResponseException e) {
        if (e.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
            return false;
        }

        throw e;
    }

    if (recursive && head.isDirectory()) {
        LOG.debug("Recursively deleting path: {}", mantaPath);
        client.deleteRecursive(mantaPath);
    } else {
        LOG.debug("Deleting path: {}", mantaPath);
        client.delete(mantaPath);
    }

    return !client.existsAndIsAccessible(mantaPath);
}
 
开发者ID:joyent,项目名称:hadoop-manta,代码行数:29,代码来源:MantaFileSystem.java

示例6: isDirectory

import com.joyent.manta.exception.MantaClientHttpResponseException; //导入依赖的package包/类
@Override
public boolean isDirectory(final Path path) throws IOException {
    try {
        return client.head(mantaPath(path)).isDirectory();
    } catch (MantaClientHttpResponseException e) {
        /* We imitate the behavior of FileSystem.isDirectory, by changing a
         * FileNotFoundException into a false return value. */
        if (e.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
            return false;
        }

        throw e;
    }
}
 
开发者ID:joyent,项目名称:hadoop-manta,代码行数:15,代码来源:MantaFileSystem.java

示例7: truncate

import com.joyent.manta.exception.MantaClientHttpResponseException; //导入依赖的package包/类
@Override
public boolean truncate(final Path path, final long newLength) throws IOException {
    final String mantaPath = mantaPath(path);

    final String contentType;

    try {
        MantaObject head = client.head(mantaPath);
        contentType = head.getContentType();
    } catch (MantaClientHttpResponseException e) {
        if (e.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
            throw new FileNotFoundException(mantaPath);
        }

        throw e;
    }

    if (newLength == 0) {
        MantaHttpHeaders headers = new MantaHttpHeaders()
                .setContentType(contentType);

        client.put(mantaPath, "", headers, null);
        return true;
    }

    throw new UnsupportedOperationException("Truncating to an arbitrary length higher "
            + "than zero is not supported at this time");
}
 
开发者ID:joyent,项目名称:hadoop-manta,代码行数:29,代码来源:MantaFileSystem.java

示例8: getUsed

import com.joyent.manta.exception.MantaClientHttpResponseException; //导入依赖的package包/类
/**
 * Return the total size of all files in the filesystem.
 */
@Override
public long getUsed() throws IOException {
    String usageFilePath = String.format("%s/reports/usage/storage/latest",
            config.getMantaHomeDirectory());

    String json = null;

    try {
         json = client.getAsString(usageFilePath);
    } catch (MantaClientHttpResponseException e) {
        if (e.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
            String msg = "Usage report file not found. Typically it will take"
                    + "one day to generate for a new account";
            throw new FileNotFoundException(msg);
        }
    }

    Preconditions.checkNotNull(json, "Response from usage inquiry shouldn't be null");

    @SuppressWarnings("unchecked")
    Map<String, Map<String, String>> storage =
            (Map<String, Map<String, String>>)new Gson()
            .fromJson(json, Map.class).get("storage");

    return storage.values().stream()
            .mapToLong(value -> Long.parseLong(value.getOrDefault("bytes", "0")))
            .sum();
}
 
开发者ID:joyent,项目名称:hadoop-manta,代码行数:32,代码来源:MantaFileSystem.java

示例9: copyFromLocalFile

import com.joyent.manta.exception.MantaClientHttpResponseException; //导入依赖的package包/类
/**
 * Copies a file from the local system to the Manta object store.
 *
 * @param delSrc    whether to delete the source
 * @param overwrite whether to overwrite an existing file
 * @param src       file source path
 * @param dst       file destination
 */
@Override
public void copyFromLocalFile(final boolean delSrc, final boolean overwrite,
                              final Path src, final Path dst) throws IOException {
    String mantaPath = mantaPath(dst);

    LOG.debug("Copying local file [{}] to [{}]", src, dst);

    if (!overwrite) {
        try {
            MantaObject head = client.head(mantaPath);
            if (!head.isDirectory()) {
                throw new IOException("Can't copy file because destination "
                        + "already exists: " + dst);
            }
        } catch (MantaClientHttpResponseException e) {
            // 404 means we are good to go and not overwriting,
            // so we throw any error that is not a 404
            if (e.getStatusCode() != HttpStatus.SC_NOT_FOUND) {
                throw e;
            }

            // Make any missing parent paths
            Path parent = dst.getParent();
            LOG.debug("Creating parent directory: {}", parent);
            client.putDirectory(mantaPath(parent), true);
        }
    }

    LocalFileSystem localFs = getLocal(getConf());
    File localFile = localFs.pathToFile(src);

    /* We used the default copy implementation if it is a wildcard copy
     * because we don't support wildcard copy in the Manta SDK yet. */
    if (localFile.isDirectory()) {
        super.copyFromLocalFile(delSrc, overwrite, src, dst);
        return;
    }

    client.put(mantaPath, localFile);

    if (delSrc) {
        Files.delete(localFile.toPath());
    }
}
 
开发者ID:joyent,项目名称:hadoop-manta,代码行数:53,代码来源:MantaFileSystem.java

示例10: copyToLocalFile

import com.joyent.manta.exception.MantaClientHttpResponseException; //导入依赖的package包/类
/**
 * The src file is under FS, and the dst is on the local disk. Copy it from FS
 * control to the local dst name. delSrc indicates if the src will be removed
 * or not. useRawLocalFileSystem indicates whether to use RawLocalFileSystem
 * as local file system or not. RawLocalFileSystem is non crc file system.So,
 * It will not create any crc files at local.
 *
 * @param delSrc                whether to delete the src
 * @param src                   path
 * @param dst                   path
 * @param useRawLocalFileSystem whether to use RawLocalFileSystem as local file system or not.
 * @throws IOException - if any IO error
 */
@Override
public void copyToLocalFile(final boolean delSrc, final Path src,
                            final Path dst, final boolean useRawLocalFileSystem) throws IOException {
    /* If we can't get a reference to a File object, then we are better off
     * relying on the default implementation of this method.
     */
    if (useRawLocalFileSystem) {
        super.copyToLocalFile(delSrc, src, dst, useRawLocalFileSystem);
        return;
    }

    Configuration conf = getConf();
    LocalFileSystem local = getLocal(conf);
    File localFile = local.pathToFile(dst);
    String mantaPath = mantaPath(src);

    try {
        MantaObject head = client.head(mantaPath);

        /* We don't support wildcard copy yet, so we rely on the default
         * implementation of this method. */
        if (head.isDirectory()) {
            super.copyToLocalFile(delSrc, src, dst, useRawLocalFileSystem);
            return;
        }

    } catch (MantaClientHttpResponseException e) {
        if (e.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
            throw new FileNotFoundException(mantaPath);
        }

        throw e;
    }

    try (MantaObjectInputStream in = client.getAsInputStream(mantaPath)) {
        Files.copy(in, localFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
    }

    if (delSrc) {
        client.delete(mantaPath);
    }
}
 
开发者ID:joyent,项目名称:hadoop-manta,代码行数:56,代码来源:MantaFileSystem.java


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