當前位置: 首頁>>代碼示例>>Java>>正文


Java S3ObjectInputStream.close方法代碼示例

本文整理匯總了Java中com.amazonaws.services.s3.model.S3ObjectInputStream.close方法的典型用法代碼示例。如果您正苦於以下問題:Java S3ObjectInputStream.close方法的具體用法?Java S3ObjectInputStream.close怎麽用?Java S3ObjectInputStream.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.amazonaws.services.s3.model.S3ObjectInputStream的用法示例。


在下文中一共展示了S3ObjectInputStream.close方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: readData

import com.amazonaws.services.s3.model.S3ObjectInputStream; //導入方法依賴的package包/類
/**
 * S3 block read would be achieved through the AmazonS3 client. Following
 * are the steps to achieve: (1) Create the objectRequest from bucketName
 * and filePath. (2) Set the range to the above created objectRequest. (3)
 * Get the object portion through AmazonS3 client API. (4) Get the object
 * content from the above object portion.
 *
 * @param bytesFromCurrentOffset
 *          bytes read till now from current offset
 * @param bytesToFetch
 *          the number of bytes to be fetched
 * @return the number of bytes read, -1 if 0 bytes read
 * @throws IOException
 */

@Override
protected int readData(final long bytesFromCurrentOffset, final int bytesToFetch) throws IOException
{
  GetObjectRequest rangeObjectRequest = new GetObjectRequest(s3Params.bucketName, s3Params.filePath);
  rangeObjectRequest.setRange(offset + bytesFromCurrentOffset, offset + bytesFromCurrentOffset + bytesToFetch - 1);
  S3Object objectPortion = s3Params.s3Client.getObject(rangeObjectRequest);
  S3ObjectInputStream wrappedStream = objectPortion.getObjectContent();
  buffer = ByteStreams.toByteArray(wrappedStream);
  wrappedStream.close();
  int bufferLength = buffer.length;
  if (bufferLength <= 0) {
    return -1;
  }
  return bufferLength;
}
 
開發者ID:apache,項目名稱:apex-malhar,代碼行數:31,代碼來源:S3RecordReader.java

示例2: readEntity

import com.amazonaws.services.s3.model.S3ObjectInputStream; //導入方法依賴的package包/類
/**
 * S3 block read would be achieved through the AmazonS3 client. Following are the steps to achieve:
 * (1) Create the objectRequest from bucketName and filePath.
 * (2) Set the range to the above created objectRequest.
 * (3) Get the object portion through AmazonS3 client API.
 * (4) Get the object content from the above object portion.
 * @return the block entity
 * @throws IOException
 */
@Override
protected Entity readEntity() throws IOException
{
  entity.clear();
  GetObjectRequest rangeObjectRequest = new GetObjectRequest(
      bucketName, filePath);
  rangeObjectRequest.setRange(offset, blockMetadata.getLength() - 1);
  S3Object objectPortion = s3Client.getObject(rangeObjectRequest);
  S3ObjectInputStream wrappedStream = objectPortion.getObjectContent();
  byte[] record = ByteStreams.toByteArray(wrappedStream);
  entity.setUsedBytes(record.length);
  entity.setRecord(record);
  wrappedStream.close();
  return entity;
}
 
開發者ID:apache,項目名稱:apex-malhar,代碼行數:25,代碼來源:S3BlockReader.java

示例3: read

import com.amazonaws.services.s3.model.S3ObjectInputStream; //導入方法依賴的package包/類
@Override
public int read(final byte[] b, final int off, final int len)
	throws IOException
{
	final S3Object object =
		s3.getObject(new GetObjectRequest(bucketName, key).withRange(pos, pos +
			len));

	final S3ObjectInputStream stream = object.getObjectContent();
	final int r = stream.read(b, off, len);
	stream.close();
	pos += r;
	return r;
}
 
開發者ID:dpwrussell,項目名稱:bfs3,代碼行數:15,代碼來源:AmazonS3Handle.java

示例4: download

import com.amazonaws.services.s3.model.S3ObjectInputStream; //導入方法依賴的package包/類
/**
 * Download a file
 */
@Override
public boolean download(String localFile) {
	try {
		if (!isFile()) return false;

		S3Object s3object = getS3().getObject(new GetObjectRequest(bucketName, key));
		if (verbose) System.out.println("Downloading '" + this + "'");
		updateInfo(s3object);

		// Create local file
		mkdirsLocal(localFile);
		FileOutputStream os = new FileOutputStream(getLocalPath());

		// Copy S3 object to file
		S3ObjectInputStream is = s3object.getObjectContent();
		int count = 0, total = 0, lastShown = 0;
		byte data[] = new byte[BUFFER_SIZE];
		while ((count = is.read(data, 0, BUFFER_SIZE)) != -1) {
			os.write(data, 0, count);
			total += count;

			if (verbose) {
				// Show every MB
				if ((total - lastShown) > (1024 * 1024)) {
					System.err.print(".");
					lastShown = total;
				}
			}
		}
		if (verbose) System.err.println("");

		// Close streams
		is.close();
		os.close();
		if (verbose) Timer.showStdErr("Donwload finished. Total " + total + " bytes.");

		// Update last modified info
		updateLocalFileLastModified();

		return true;
	} catch (Exception e) {
		Timer.showStdErr("ERROR while downloading " + this);
		throw new RuntimeException(e);
	}
}
 
開發者ID:pcingola,項目名稱:BigDataScript,代碼行數:49,代碼來源:DataS3.java


注:本文中的com.amazonaws.services.s3.model.S3ObjectInputStream.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。