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


Java IOUtils类代码示例

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


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

示例1: parse

import com.amazonaws.util.IOUtils; //导入依赖的package包/类
/**
 * Helper method that parses a JSON object from a resource on the classpath
 * as an instance of the provided type.
 *
 * @param resource
 *            the path to the resource (relative to this class)
 * @param clazz
 *            the type to parse the JSON into
 */
public static <T> T parse(String resource, Class<T> clazz)
		throws IOException {

	InputStream stream = TestUtils.class.getResourceAsStream(resource);
	try {
		if (clazz == S3Event.class) {
			String json = IOUtils.toString(stream);
			S3EventNotification event = S3EventNotification.parseJson(json);

			@SuppressWarnings("unchecked")
			T result = (T) new S3Event(event.getRecords());
			return result;

		} else if (clazz == SNSEvent.class) {
			return snsEventMapper.readValue(stream, clazz);
		} else if (clazz == DynamodbEvent.class) {
			return dynamodbEventMapper.readValue(stream, clazz);
		} else {
			return mapper.readValue(stream, clazz);
		}
	} finally {
		stream.close();
	}
}
 
开发者ID:EixoX,项目名称:jetfuel,代码行数:34,代码来源:TestUtils.java

示例2: parse

import com.amazonaws.util.IOUtils; //导入依赖的package包/类
/**
 * Helper method that parses a JSON object from a resource on the classpath
 * as an instance of the provided type.
 *
 * @param resource the path to the resource (relative to this class)
 * @param clazz the type to parse the JSON into
 */
public static <T> T parse(String resource, Class<T> clazz)
        throws IOException {

    InputStream stream = TestUtils.class.getResourceAsStream(resource);
    try {
        if (clazz == S3Event.class) {
            String json = IOUtils.toString(stream);
            S3EventNotification event = S3EventNotification.parseJson(json);

            @SuppressWarnings("unchecked")
            T result = (T) new S3Event(event.getRecords());
            return result;

        } else {
            return mapper.readValue(stream, clazz);
        }
    } finally {
        stream.close();
    } 
}
 
开发者ID:taichi,项目名称:sirusi,代码行数:28,代码来源:TestUtils.java

示例3: writeLocalFile

import com.amazonaws.util.IOUtils; //导入依赖的package包/类
private void writeLocalFile(
        final S3Object s3Object, 
        final File file) {

    try(FileOutputStream fileOutputStream 
            = new FileOutputStream(file)) {

        IOUtils.copy(
                s3Object.getObjectContent(), 
                fileOutputStream);
        
    } catch (IOException ioException) {
        throw new SecretsLockerException(
                ioException);
    }

    file.deleteOnExit();
}
 
开发者ID:eonian-technologies,项目名称:secrets-locker,代码行数:19,代码来源:S3SecretsLocker.java

示例4: copyOneObject

import com.amazonaws.util.IOUtils; //导入依赖的package包/类
@Test
public void copyOneObject() throws Exception {
  client.putObject("source", "data", inputData);

  Path sourceBaseLocation = new Path("s3://source/");
  Path replicaLocation = new Path("s3://target/");
  List<Path> sourceSubLocations = new ArrayList<>();
  S3S3Copier s3s3Copier = newS3S3Copier(sourceBaseLocation, sourceSubLocations, replicaLocation);
  Metrics metrics = s3s3Copier.copy();
  assertThat(metrics.getBytesReplicated(), is(7L));
  assertThat(metrics.getMetrics().get(S3S3CopierMetrics.Metrics.TOTAL_BYTES_TO_REPLICATE.name()), is(7L));
  S3Object object = client.getObject("target", "data");
  String data = IOUtils.toString(object.getObjectContent());
  assertThat(data, is("bar foo"));
  assertThat(registry.getGauges().containsKey(RunningMetrics.S3S3_CP_BYTES_REPLICATED.name()), is(true));
}
 
开发者ID:HotelsDotCom,项目名称:circus-train,代码行数:17,代码来源:S3S3CopierTest.java

示例5: copyMultipleObjects

import com.amazonaws.util.IOUtils; //导入依赖的package包/类
@Test
public void copyMultipleObjects() throws Exception {
  // Making sure we only request 1 file at the time so we need to loop
  ListObjectsRequestFactory mockListObjectRequestFactory = Mockito.mock(ListObjectsRequestFactory.class);
  when(mockListObjectRequestFactory.newInstance()).thenReturn(new ListObjectsRequest().withMaxKeys(1));

  client.putObject("source", "bar/data1", inputData);
  client.putObject("source", "bar/data2", inputData);

  Path sourceBaseLocation = new Path("s3://source/bar/");
  Path replicaLocation = new Path("s3://target/foo/");
  List<Path> sourceSubLocations = new ArrayList<>();
  S3S3Copier s3s3Copier = new S3S3Copier(sourceBaseLocation, sourceSubLocations, replicaLocation, s3ClientFactory,
      transferManagerFactory, mockListObjectRequestFactory, registry, s3S3CopierOptions);
  Metrics metrics = s3s3Copier.copy();
  assertThat(metrics.getBytesReplicated(), is(14L));

  S3Object object1 = client.getObject("target", "foo/data1");
  String data1 = IOUtils.toString(object1.getObjectContent());
  assertThat(data1, is("bar foo"));
  S3Object object2 = client.getObject("target", "foo/data2");
  String data2 = IOUtils.toString(object2.getObjectContent());
  assertThat(data2, is("bar foo"));
}
 
开发者ID:HotelsDotCom,项目名称:circus-train,代码行数:25,代码来源:S3S3CopierTest.java

示例6: createSnsEvent

import com.amazonaws.util.IOUtils; //导入依赖的package包/类
private SNSEvent createSnsEvent(final String githubEvent) {
    SNSEvent.SNS sns = new SNSEvent.SNS();
    sns.setMessageAttributes(new HashMap<String, SNSEvent.MessageAttribute>(1, 1) {
        {
            SNSEvent.MessageAttribute attr = new SNSEvent.MessageAttribute();
            attr.setValue(githubEvent);
            put("X-Github-Event", attr);
        }
    });
    try (InputStream is = getClass().getResourceAsStream("/github-push-payload.json")) {
        sns.setMessage(IOUtils.toString(is));
    }
    catch (IOException e) {
        throw new IllegalArgumentException(e);
    }

    SNSEvent.SNSRecord record = new SNSEvent.SNSRecord();
    record.setSns(sns);

    SNSEvent snsEvent = new SNSEvent();
    snsEvent.setRecords(Collections.singletonList(record));
    return snsEvent;
}
 
开发者ID:berlam,项目名称:github-bucket,代码行数:24,代码来源:LambdaTest.java

示例7: 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

示例8: handleErrorResponse

import com.amazonaws.util.IOUtils; //导入依赖的package包/类
private void handleErrorResponse(InputStream errorStream, int statusCode, String responseMessage) throws IOException {
    String errorCode = null;

    // Parse the error stream returned from the service.
    if(errorStream != null) {
        String errorResponse = IOUtils.toString(errorStream);

        try {
            JsonNode node = Jackson.jsonNodeOf(errorResponse);
            JsonNode code = node.get("code");
            JsonNode message = node.get("message");
            if (code != null && message != null) {
                errorCode = code.asText();
                responseMessage = message.asText();
            }
        } catch (Exception exception) {
            LOG.debug("Unable to parse error stream");
        }
    }

    AmazonServiceException ase = new AmazonServiceException(responseMessage);
    ase.setStatusCode(statusCode);
    ase.setErrorCode(errorCode);
    throw ase;
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:26,代码来源:EC2CredentialsUtils.java

示例9: drainInputStream

import com.amazonaws.util.IOUtils; //导入依赖的package包/类
public static byte[] drainInputStream(InputStream inputStream) {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

    try {
        byte[] buffer = new byte[1024];
        long bytesRead = 0;
        while ((bytesRead = inputStream.read(buffer)) > -1) {
            byteArrayOutputStream.write(buffer, 0, (int) bytesRead);
        }
        return byteArrayOutputStream.toByteArray();
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        IOUtils.closeQuietly(byteArrayOutputStream, null);
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:17,代码来源:ApacheDefaultHttpRequestFactoryTest.java

示例10: drainInputStream

import com.amazonaws.util.IOUtils; //导入依赖的package包/类
/**
 * Reads to the end of the inputStream returning a byte array of the contents
 * 
 * @param inputStream
 *            InputStream to drain
 * @return Remaining data in stream as a byte array
 */
public static byte[] drainInputStream(InputStream inputStream) {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

    try {
        byte[] buffer = new byte[1024];
        long bytesRead = 0;
        while ((bytesRead = inputStream.read(buffer)) > -1) {
            byteArrayOutputStream.write(buffer, 0, (int) bytesRead);
        }
        return byteArrayOutputStream.toByteArray();
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        IOUtils.closeQuietly(byteArrayOutputStream, null);
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:24,代码来源:InputStreamUtils.java

示例11: putLocalObject

import com.amazonaws.util.IOUtils; //导入依赖的package包/类
/**
 * Used for performance testing purposes only.
 */
private void putLocalObject(final UploadObjectRequest reqIn,
        OutputStream os) throws IOException {
    UploadObjectRequest req = reqIn.clone();

    final File fileOrig = req.getFile();
    final InputStream isOrig = req.getInputStream();

    if (isOrig == null) {
        if (fileOrig == null)
            throw new IllegalArgumentException("Either a file lor input stream must be specified");
        req.setInputStream(new FileInputStream(fileOrig));
        req.setFile(null);
    }

    try {
        IOUtils.copy(req.getInputStream(), os);
    } finally {
        cleanupDataSource(req, fileOrig, isOrig,
                req.getInputStream(), log);
        IOUtils.closeQuietly(os, log);
    }
    return;
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:27,代码来源:AmazonS3Client.java

示例12: close

import com.amazonaws.util.IOUtils; //导入依赖的package包/类
/**
 * {@inheritDoc}
 *
 * Delegates to {@link S3ObjectInputStream#abort()} if there is any data
 * remaining in the stream. Otherwise, it safely closes the stream.
 *
 * @see {@link S3ObjectInputStream#abort()}
 */
@Override
public void close() throws IOException {
    if (bytesRead >= contentLength || eofReached) {
        super.close();
    } else {
        LOG.warn(
                "Not all bytes were read from the S3ObjectInputStream, aborting HTTP connection. This is likely an error and " +
                "may result in sub-optimal behavior. Request only the bytes you need via a ranged GET or drain the input " +
                "stream after use.");
        if (httpRequest != null) {
            httpRequest.abort();
        }
        IOUtils.closeQuietly(in, null);
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:24,代码来源:S3AbortableInputStream.java

示例13: close

import com.amazonaws.util.IOUtils; //导入依赖的package包/类
@Override
public void close() throws IOException {
    // If not already closed, then close the input stream.
    if(!this.closed) {
        this.closed = true;
        // if the user read to the end of the virtual stream, then drain
        // the wrapped stream so the HTTP client can keep this connection
        // alive if possible.
        // This should not have too much overhead since if we've reached the
        // end of the virtual stream, there should be at most 31 bytes left
        // (2 * JceEncryptionConstants.SYMMETRIC_CIPHER_BLOCK_SIZE - 1) in the
        // stream.
        // See: S3CryptoModuleBase#getCipherBlockUpperBound
         if (this.virtualAvailable == 0) {
             IOUtils.drainInputStream(decryptedContents);
        }
        this.decryptedContents.close();
    }
    abortIfNeeded();
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:21,代码来源:AdjustedRangeInputStream.java

示例14: putLocalObjectSecurely

import com.amazonaws.util.IOUtils; //导入依赖的package包/类
@Override
public final void putLocalObjectSecurely(final UploadObjectRequest reqIn,
        String uploadId, OutputStream os) throws IOException {
    UploadObjectRequest req = reqIn.clone();

    final File fileOrig = req.getFile();
    final InputStream isOrig = req.getInputStream();

    final T uploadContext = multipartUploadContexts.get(uploadId);
    ContentCryptoMaterial cekMaterial = uploadContext.getContentCryptoMaterial();
    req = wrapWithCipher(req, cekMaterial);

    try {
        IOUtils.copy(req.getInputStream(), os);
        // so it won't crap out with a false negative at the end; (Not
        // really relevant here)
        uploadContext.setHasFinalPartBeenSeen(true);
    } finally {
        cleanupDataSource(req, fileOrig, isOrig,
                req.getInputStream(), log);
        IOUtils.closeQuietly(os, log);
    }
    return;
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:25,代码来源:S3CryptoModuleBase.java

示例15: 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


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