into the void

ソフトウェアに関する雑多な調査日記

Amazon Glacierを使ってiPhotoの写真をバックアップしてみる(其の参)

Amazon SNSからNotification メールが来てたので早速ダウンロードしてみた。

public static void downloadDo() throws Exception{
		AWSCredentials credentials = new PropertiesCredentials
				(TestDownloadOperation.class.getResourceAsStream("AwsCredentials.properties"));
		client = new AmazonGlacierClient(credentials);
		client.setEndpoint("https://glacier.ap-northeast-1.amazonaws.com");
		
		GetJobOutputRequest request = new GetJobOutputRequest();
		request.withJobId(jobId);
		request.withVaultName(vaultName);
		GetJobOutputResult result = client.getJobOutput(request);
		InputStream input = new BufferedInputStream(result.getBody());
		OutputStream output = null;
		try{
			output = new BufferedOutputStream(new FileOutputStream(downloadFilePath));
			byte[] buffer = new byte[1024*1024];
			int byteRead = 0;
			long start = System.currentTimeMillis();
			System.out.println("Download Start");
			do{
				byteRead = input.read(buffer);
				if(byteRead > 0){
					output.write(buffer, 0, byteRead);
					System.out.print(".");
				}
			}while(byteRead > 0);
			long end = System.currentTimeMillis();
			System.out.println("Download Finished");
			System.out.println("Elapsed time = " + (end - start));
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			input.close();
			output.close();
		}
	}
	

無事にテキストファイルもtar.gzの圧縮ファイルもダウンロードできた。
あと気になるのは請求額。