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


Java S3Service.getObject方法代码示例

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


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

示例1: makeObjects

import org.jets3t.service.S3Service; //导入方法依赖的package包/类
void makeObjects()
    throws IOException, URISyntaxException, ServiceException, NoSuchAlgorithmException {
  // Configure the service
  S3Service s3Service = testUtil.configureS3Service(hostName, PROXY_PORT);

  // Prepare objects inside MasterBucket; PUT and READ
  int randInt = Math.abs(new Random().nextInt() % 10) + 2;
  for (int i = 0; i < randInt; i++) {
    String oid = (useMasterObject) ? masterObjectName :
        "object_" + id + "_" + i;
    byte[] data = new byte[SMALL_SIZE];
    for (int d = 0; d < SMALL_SIZE; d++) {
      data[i] = (byte) (d % 256);
    }
    S3Object s3Object = new S3Object(oid, data);
    s3Service.putObject(masterBucket, s3Object);
    S3Object object =
        s3Service.getObject(masterBucket, s3Object.getKey());
    InputStream dataInputStream = object.getDataInputStream();
    for (int j = 0; j < SMALL_SIZE; j++) {
      int read = dataInputStream.read();
      if (read == -1) fail();
    }
    assertEquals(-1, dataInputStream.read());
    dataInputStream.close();
  }

  // Shutdown the service
  s3Service.shutdown();
  passed = true;
}
 
开发者ID:WANdisco,项目名称:s3hdfs,代码行数:32,代码来源:TestConcurrency.java

示例2: main

import org.jets3t.service.S3Service; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException, S3ServiceException {
	// We're accessing a publicly available bucket so don't need to fill in our credentials
	S3Service s3s = new RestS3Service(null);
	
	// Let's grab a file out of the CommonCrawl S3 bucket
	String fn = "common-crawl/crawl-data/CC-MAIN-2013-48/segments/1386163035819/warc/CC-MAIN-20131204131715-00000-ip-10-33-133-15.ec2.internal.warc.gz";
	S3Object f = s3s.getObject("aws-publicdatasets", fn, null, null, null, null, null, null);
	
	// The file name identifies the ArchiveReader and indicates if it should be decompressed
	ArchiveReader ar = WARCReaderFactory.get(fn, f.getDataInputStream(), true);
	
	// Once we have an ArchiveReader, we can work through each of the records it contains
	int i = 0;
	for(ArchiveRecord r : ar) {
		// The header file contains information such as the type of record, size, creation time, and URL
		System.out.println("Header: " + r.getHeader());
		System.out.println("URL: " + r.getHeader().getUrl());
		System.out.println();
		
		// If we want to read the contents of the record, we can use the ArchiveRecord as an InputStream
		// Create a byte array that is as long as all the record's stated length
		byte[] rawData = new byte[r.available()];
		r.read(rawData);
		// Note: potential optimization would be to have a large buffer only allocated once
		
		// Why don't we convert it to a string and print the start of it? Let's hope it's text!
		String content = new String(rawData);
		System.out.println(content.substring(0, Math.min(500, content.length())));
		System.out.println((content.length() > 500 ? "..." : ""));
		
		// Pretty printing to make the output more readable 
		System.out.println("=-=-=-=-=-=-=-=-=");
		if (i++ > 4) break; 
	}
}
 
开发者ID:Smerity,项目名称:cc-warc-examples,代码行数:36,代码来源:S3ReaderTest.java

示例3: main

import org.jets3t.service.S3Service; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException, S3ServiceException {
		// We're accessing a publicly available bucket so don't need to fill in our credentials
		S3Service s3s = new RestS3Service(null);
		
		// Let's grab a file out of the CommonCrawl S3 bucket
		String fn = "common-crawl/crawl-data/CC-MAIN-2013-48/segments/1386163035819/warc/CC-MAIN-20131204131715-00000-ip-10-33-133-15.ec2.internal.warc.gz";
		S3Object f = s3s.getObject("aws-publicdatasets", fn, null, null, null, null, null, null);
		
		// The file name identifies the ArchiveReader and indicates if it should be decompressed
		ArchiveReader ar;
		try {
			ar = WARCReaderFactory.get(fn, f.getDataInputStream(), true);
			
			// Once we have an ArchiveReader, we can work through each of the records it contains
			int i = 0;
			for(ArchiveRecord r : ar) {
				// The header file contains information such as the type of record, size, creation time, and URL
				System.out.println("Header: " + r.getHeader());
				System.out.println("URL: " + r.getHeader().getUrl());
				
//			System.out.println(r.);
				
				
				// If we want to read the contents of the record, we can use the ArchiveRecord as an InputStream
				// Create a byte array that is as long as all the record's stated length
				byte[] rawData = new byte[r.available()];
				r.read(rawData);
				// Note: potential optimization would be to have a large buffer only allocated once
				
				// Why don't we convert it to a string and print the start of it? Let's hope it's text!
				String content = new String(rawData);
				System.out.println(content.substring(0, Math.min(500, content.length())));
				System.out.println((content.length() > 500 ? "..." : ""));
				
				// Pretty printing to make the output more readable 
				System.out.println("=-=-=-=-=-=-=-=-=");
				if (i++ > 4) break; 
			}
		} catch (ServiceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
 
开发者ID:TeamHG-Memex,项目名称:common-crawl-mapreduce,代码行数:44,代码来源:S3ReaderTest.java

示例4: generateFilename

import org.jets3t.service.S3Service; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public String generateFilename(IScope scope, String name, String extension, GenerationType type) {
   	logger.debug("Get stream directory: scope={}, name={}, type={}", new Object[]{scope, name, type.toString()});		
	StringBuilder path = new StringBuilder();
	// get the session id
	IConnection conn = Red5.getConnectionLocal();
	if (conn.hasAttribute("sessionId")) {
		String sessionId = conn.getStringAttribute("sessionId");
		path.append(sessionId);
		path.append('/');
	}
	// add resources name
	path.append(name);
	// add extension if we have one
       if (extension != null){
           // add extension
       	path.append(extension);
       }		
	// determine whether its playback or record
	if (type.equals(GenerationType.PLAYBACK)) {
		logger.debug("Playback path used");
		// look on s3 for the file first	
		boolean found = false;
		try {
			S3Service s3Service = new RestS3Service(awsCredentials);
			S3Bucket bucket = s3Service.getBucket(bucketName);
			String objectKey = path.toString();
			S3Object file = s3Service.getObject(bucket, objectKey);
			if (file != null) {
				S3Object details = s3Service.getObjectDetails(bucket, objectKey);
				logger.debug("Details - key: {} content type: {}", details.getKey(), details.getContentType()); 
				path.insert(0, bucket.getLocation());
				// set found flag
				found = true;
			}
		} catch (S3ServiceException e) {
			logger.warn("Error looking up media file", e);
		}
		// use local path
		if (!found) {
			logger.debug("File was not found on S3, using local playback location");
			path.insert(0, playbackPath);
		}
	} else {
		logger.debug("Record path used");
		path.insert(0, recordPath);
	}

       String fileName = path.toString();
       logger.debug("Generated filename: {}", fileName);
       return fileName;
}
 
开发者ID:Red5,项目名称:red5-examples,代码行数:53,代码来源:S3FilenameGenerator.java


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