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


Java IOUtils.toByteArray方法代码示例

本文整理汇总了Java中com.amazonaws.util.IOUtils.toByteArray方法的典型用法代码示例。如果您正苦于以下问题:Java IOUtils.toByteArray方法的具体用法?Java IOUtils.toByteArray怎么用?Java IOUtils.toByteArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.amazonaws.util.IOUtils的用法示例。


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

示例1: fromStdin

import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
private byte[] fromStdin() {
    try {

        InputStream inputStream = System.in;
        BufferedReader inputReader = new BufferedReader(new InputStreamReader(inputStream));
        if (!inputReader.ready()) {
            // Interactive
            char[] secretValue = System.console().readPassword("Enter secret value:");

            if (secretValue == null) {
                throw new IllegalArgumentException("A secret value must be specified");
            }
            return asBytes(secretValue);
        } else {
            // Piped in
            return IOUtils.toByteArray(inputStream);
        }
    } catch (IOException e) {
        throw new RuntimeException("Failed to read secret value from stdin", e);
    }
}
 
开发者ID:schibsted,项目名称:strongbox,代码行数:22,代码来源:SecretModel.java

示例2: loadIndex

import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
/**
 * A method that seeks and downloads the index for the set BAM URI.
 * Seeks an index file with the same name in the BAM directory
 * in case there's no custom index URI specified
 *
 * @param bamURI an http address of the required file.
 * @return A SeekableStream optional on index file URI
 */
Optional<SeekableStream> loadIndex(AmazonS3URI bamURI) throws IOException {
    LOG.info("Trying to set index file for " + bamURI.toString());
    Optional<AmazonS3URI> index = providedIndexURI()
            .map(Optional::of)
            .orElseGet(() -> nearbyIndexURI(bamURI));

    if (!index.isPresent()) {
        LOG.info("Index wasn't provided for " + bamURI.toString());
        return Optional.empty();
    }

    LOG.info("Start download index: " + index.get());
    AmazonS3URI indexURI = index.get();
    S3InputStreamFactory streamFactory = new S3InputStreamFactory(client);
    InputStream stream = streamFactory.loadFully(indexURI);
    long fileSize = client.getFileSize(indexURI);
    byte[] buffer = IOUtils.toByteArray(stream);

    if (fileSize != buffer.length) {
        throw new IOException("Failed to fully download index " + indexURI);
    }

    LOG.info("Finished download index: " + index.get());
    return Optional.of(new SeekableMemoryStream(buffer, indexURI.toString()));
}
 
开发者ID:epam,项目名称:htsjdk-s3-plugin,代码行数:34,代码来源:IndexLoader.java

示例3: viewProfileImage

import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
@RequestMapping(value = "/image/view/{userUid}", method = RequestMethod.GET)
public ResponseEntity<byte[]> viewProfileImage(@PathVariable String userUid) {

    try {
        String imageKey = userProfileImagesFolder + "/" + userUid;
        MediaFunction mediaFunction = MediaFunction.USER_PROFILE_IMAGE;

        MediaFileRecord mediaFileRecord = mediaFileBroker.load(mediaFunction, imageKey);
        byte[] data;
        if (mediaFileRecord != null) {
            File imageFile = storageBroker.fetchFileFromRecord(mediaFileRecord);
            data = IOUtils.toByteArray(new FileInputStream(imageFile));
        } else {
            InputStream in = getClass().getResourceAsStream("/static/images/user.png");
            data = IOUtils.toByteArray(in);
        }
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.IMAGE_PNG);
        ResponseEntity<byte[]> response = new ResponseEntity(data, headers, HttpStatus.OK);
        return response;
    } catch (Exception e) {
        log.error("Failed to fetch user profile image for user with uid: " + userUid, e);
        return new ResponseEntity(null, HttpStatus.INTERNAL_SERVER_ERROR);
    }
}
 
开发者ID:grassrootza,项目名称:grassroot-platform,代码行数:26,代码来源:UserController.java

示例4: walk

import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
private boolean walk(Iterator<S3ObjectSummary> iter, ObjectId file, String path) throws IOException {
    byte[] content;
    byte[] newHash;
    LOG.debug("Start processing file: {}", path);
    try (DigestInputStream is = new DigestInputStream(repository.open(file).openStream(), DigestUtils.getMd5Digest())) {
        // Get content
        content = IOUtils.toByteArray(is);
        // Get hash
        newHash = is.getMessageDigest().digest();
    }
    if (isUploadFile(iter, path, Hex.encodeHexString(newHash))) {
        LOG.info("Uploading file: {}", path);
        ObjectMetadata bucketMetadata = new ObjectMetadata();
        bucketMetadata.setContentMD5(Base64.encodeAsString(newHash));
        bucketMetadata.setContentLength(content.length);
        // Give Tika a few hints for the content detection
        Metadata tikaMetadata = new Metadata();
        tikaMetadata.set(Metadata.RESOURCE_NAME_KEY, FilenameUtils.getName(FilenameUtils.normalize(path)));
        // Fire!
        try (InputStream bis = TikaInputStream.get(content, tikaMetadata)) {
            bucketMetadata.setContentType(TIKA_DETECTOR.detect(bis, tikaMetadata).toString());
            s3.putObject(bucket.getName(), path, bis, bucketMetadata);
            return true;
        }
    }
    LOG.info("Skipping file (same checksum): {}", path);
    return false;
}
 
开发者ID:berlam,项目名称:github-bucket,代码行数:29,代码来源:RepositoryS3.java

示例5: createJsonContent

import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
/**
 * Static factory method to create a JsonContent object from the contents of the HttpResponse
 * provided
 */
public static JsonContent createJsonContent(HttpResponse httpResponse,
                                            JsonFactory jsonFactory) {
    byte[] rawJsonContent = null;
    try {
        if (httpResponse.getContent() != null) {
            rawJsonContent = IOUtils.toByteArray(httpResponse.getContent());
        }
    } catch (Exception e) {
        LOG.info("Unable to read HTTP response content", e);
    }
    return new JsonContent(rawJsonContent, new ObjectMapper(jsonFactory)
            .configure(JsonParser.Feature.ALLOW_COMMENTS, true));
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:18,代码来源:JsonContent.java

示例6: upload

import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
public String upload(InputStream is, String fileName, String sufix, Boolean isPublic) throws Exception {
    validateFile(is, sufix);
    if (isPublic == null) {
        isPublic = Boolean.TRUE;
    }
    if (is != null && fileName != null) {

        try {
            byte[] bytes = IOUtils.toByteArray(is);
            s3Client.putObject(
                    new PutObjectRequest(
                    		cdnConfig.getName(),
                            fileName + "." + sufix,
                            new ByteArrayInputStream(bytes),
                            S3ObjectMetadata.getObjectMetadata(bytes)
                    ).withCannedAcl(isPublic ? CannedAccessControlList.PublicRead : CannedAccessControlList.AuthenticatedRead)
            );
            return fileName + "." + sufix;
        } catch (AmazonServiceException | IOException e) {
            throw new BusinessException(Validations.INVALID_S3_BUCKET_CREDENTIALS.getCode());
        } finally {
            is.close();
        }
    } else {
        throw new BusinessException(Validations.INVALID_PARAMETERS.getCode());
    }
}
 
开发者ID:KonkerLabs,项目名称:konker-platform,代码行数:28,代码来源:AwsUploadRepository.java

示例7: getFromAWSS3Storage

import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
public byte[] getFromAWSS3Storage(String name) throws Exception {
	
	AmazonS3 s3Client = new AmazonS3Client(new EnvironmentVariableCredentialsProvider());        
	S3Object object = s3Client.getObject(
	                  new GetObjectRequest(containerName, name));
	InputStream objectData = object.getObjectContent();
	return IOUtils.toByteArray(objectData);
}
 
开发者ID:ritazh,项目名称:azure-s3proxy-cf-demo,代码行数:9,代码来源:PhotoLibrary.java

示例8: getFromS3Proxy

import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
public byte[] getFromS3Proxy(String name, String key, String secret, String endpoint) throws Exception {
	System.setProperty("com.amazonaws.services.s3.disablePutObjectMD5Validation", "1"); 
	
	AWSCredentials credentials = new BasicAWSCredentials(key, secret);
	ClientConfiguration clientConfig = new ClientConfiguration().withSignerOverride("S3SignerType");
	clientConfig.setProtocol(Protocol.HTTP);
	AmazonS3 s3 = new AmazonS3Client(credentials, clientConfig);
	
    s3.setEndpoint(endpoint);      
	S3Object object = s3.getObject(
	                  new GetObjectRequest(containerName, name));
	InputStream objectData = object.getObjectContent();
	return IOUtils.toByteArray(objectData);
}
 
开发者ID:ritazh,项目名称:azure-s3proxy-cf-demo,代码行数:15,代码来源:PhotoLibrary.java

示例9: call

import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
@Override
public Void call() throws Exception {
    byte[] data = IOUtils.toByteArray(s3Client.getObject(new GetObjectRequest(bucket, key).withRange(start, end)).getObjectContent());
    channel.write(ByteBuffer.wrap(data), start);
    return null;
}
 
开发者ID:EMCECS,项目名称:ecs-samples,代码行数:7,代码来源:LargeFileDownloader.java


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