List of usage examples for com.amazonaws.services.glacier.transfer ArchiveTransferManager ArchiveTransferManager
public ArchiveTransferManager(AmazonGlacierClient glacier, AmazonSQSClient sqs, AmazonSNSClient sns)
From source file:com.brianmcmichael.sagu.AmazonDownloadRequest.java
License:Open Source License
@Override public void actionPerformed(ActionEvent e) { if (e.getSource() == jbtDownload) { archiveId = jtfDownloadField.getText().trim(); if ((archiveId.equals(""))) { JOptionPane.showMessageDialog(null, "Enter the Archive ID of the file to be requested.", "Error", JOptionPane.ERROR_MESSAGE); } else {/* ww w . ja v a2 s . com*/ SwingWorker downloadWorker = new SwingWorker() { private String archiveId = jtfDownloadField.getText().trim(); @Override protected Object doInBackground() throws Exception { // Create dumb progressbar JFrame downloadFrame = new JFrame("Downloading"); { downloadFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); final JProgressBar dumJProgressBar = new JProgressBar(JProgressBar.HORIZONTAL); dumJProgressBar.setIndeterminate(true); downloadFrame.add(dumJProgressBar, BorderLayout.NORTH); downloadFrame.setSize(300, 60); } centerDefineFrame(downloadFrame, 300, 50); String archiveId = jtfDownloadField.getText().trim(); try { String vaultName = dlVault; FileDialog fd = new FileDialog(new Frame(), "Save Archive As...", FileDialog.SAVE); fd.setFile("Save Archive As..."); fd.setDirectory(System.getProperty("user.dir")); fd.setLocation(50, 50); fd.setVisible(true); String filePath = "" + fd.getDirectory() + System.getProperty("file.separator") + fd.getFile(); File outFile = new File(filePath); if (outFile != null) { downloadFrame.setTitle("Downloading " + outFile.toString()); downloadFrame.setVisible(true); final Endpoint endpoint = Endpoint.getByIndex(locationChoice); AmazonSQSClient dlSQS = new AmazonSQSClient(dlCredentials); AmazonSNSClient dlSNS = new AmazonSNSClient(dlCredentials); dlSQS.setEndpoint(endpoint.getSQSEndpoint()); dlSNS.setEndpoint(endpoint.getSNSEndpoint()); // ArchiveTransferManager atm = new // ArchiveTransferManager(dlClient, // dlCredentials); ArchiveTransferManager atm = new ArchiveTransferManager(dlClient, dlSQS, dlSNS); atm.download("-", vaultName, archiveId, outFile); JOptionPane.showMessageDialog(null, "Sucessfully downloaded " + outFile.toString(), "Success", JOptionPane.INFORMATION_MESSAGE); downloadFrame.setVisible(false); } } catch (AmazonServiceException k) { JOptionPane.showMessageDialog(null, "The server returned an error. Wait 24 hours after submitting an archive to attempt a download. Also check that correct location of archive has been set on the previous page.", "Error", JOptionPane.ERROR_MESSAGE); System.out.println("" + k); downloadFrame.setVisible(false); } catch (AmazonClientException i) { JOptionPane.showMessageDialog(null, "Client Error. Check that all fields are correct. Archive not downloaded.", "Error", JOptionPane.ERROR_MESSAGE); downloadFrame.setVisible(false); } catch (Exception j) { JOptionPane.showMessageDialog(null, "Archive not found. Unspecified Error.", "Error", JOptionPane.ERROR_MESSAGE); downloadFrame.setVisible(false); } return null; } }; downloadWorker.execute(); try { Thread.sleep(500); } catch (InterruptedException e1) { e1.printStackTrace(); } this.setVisible(false); dispose(); } } else if (e.getSource() == jbtBack) { this.setVisible(false); dispose(); } else { JOptionPane.showMessageDialog(this, "Please choose a valid action."); } }
From source file:com.brianmcmichael.sagu.ui.AmazonDownloadRequest.java
License:Open Source License
@Override public void actionPerformed(ActionEvent e) { if (e.getSource() == jbtDownload) { archiveId = jtfDownloadField.getText().trim(); if ((archiveId.equals(""))) { JOptionPane.showMessageDialog(null, "Enter the Archive ID of the file to be requested.", "Error", JOptionPane.ERROR_MESSAGE); } else {/*from w w w .ja v a 2 s. c o m*/ SwingWorker<Object, Void> downloadWorker = new SwingWorker<Object, Void>() { private String archiveId = jtfDownloadField.getText().trim(); @Override protected Void doInBackground() throws Exception { // Create dumb progressbar JFrame downloadFrame = new JFrame("Downloading"); { downloadFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); final JProgressBar dumJProgressBar = new JProgressBar(JProgressBar.HORIZONTAL); dumJProgressBar.setIndeterminate(true); downloadFrame.add(dumJProgressBar, BorderLayout.NORTH); downloadFrame.setSize(300, 60); } centerDefineFrame(downloadFrame, 300, 50); try { String vaultName = dlVault; FileDialog fd = new FileDialog(new Frame(), "Save Archive As...", FileDialog.SAVE); fd.setFile("Save Archive As..."); fd.setDirectory(System.getProperty("user.dir")); fd.setLocation(50, 50); fd.setVisible(true); String filePath = "" + fd.getDirectory() + System.getProperty("file.separator") + fd.getFile(); File outFile = new File(filePath); if (outFile != null) { downloadFrame.setTitle("Downloading " + outFile.toString()); downloadFrame.setVisible(true); final Endpoint endpoint = Endpoint.getByIndex(locationChoice); AmazonSQSClient dlSQS = new AmazonSQSClient(dlCredentials); AmazonSNSClient dlSNS = new AmazonSNSClient(dlCredentials); dlSQS.setEndpoint(endpoint.getSQSEndpoint()); dlSNS.setEndpoint(endpoint.getSNSEndpoint()); // ArchiveTransferManager atm = new // ArchiveTransferManager(dlClient, // dlCredentials); ArchiveTransferManager atm = new ArchiveTransferManager(dlClient, dlSQS, dlSNS); atm.download("-", vaultName, archiveId, outFile); JOptionPane.showMessageDialog(null, "Sucessfully downloaded " + outFile.toString(), "Success", JOptionPane.INFORMATION_MESSAGE); downloadFrame.setVisible(false); } } catch (AmazonServiceException k) { JOptionPane.showMessageDialog(null, "The server returned an error. Wait 24 hours after submitting an archive to attempt a download. Also check that correct location of archive has been set on the previous page.", "Error", JOptionPane.ERROR_MESSAGE); System.out.println("" + k); downloadFrame.setVisible(false); } catch (AmazonClientException i) { JOptionPane.showMessageDialog(null, "Client Error. Check that all fields are correct. Archive not downloaded.", "Error", JOptionPane.ERROR_MESSAGE); downloadFrame.setVisible(false); } catch (Exception j) { JOptionPane.showMessageDialog(null, "Archive not found. Unspecified Error.", "Error", JOptionPane.ERROR_MESSAGE); downloadFrame.setVisible(false); } return null; } }; downloadWorker.execute(); try { Thread.sleep(500); } catch (InterruptedException e1) { e1.printStackTrace(); } this.setVisible(false); dispose(); } } else if (e.getSource() == jbtBack) { this.setVisible(false); dispose(); } else { JOptionPane.showMessageDialog(this, "Please choose a valid action."); } }
From source file:com.brianmcmichael.SimpleGlacierUploader.AmazonDownloadRequest.java
License:Open Source License
@Override public void actionPerformed(ActionEvent e) { if (e.getSource() == jbtDownload) { archiveId = jtfDownloadField.getText().trim(); if ((archiveId.equals(""))) { JOptionPane.showMessageDialog(null, "Enter the Archive ID of the file to be requested.", "Error", JOptionPane.ERROR_MESSAGE); } else {/*from w w w.j a v a 2 s. c o m*/ SwingWorker downloadWorker = new SwingWorker() { private String archiveId = jtfDownloadField.getText().trim(); @Override protected Object doInBackground() throws Exception { // Create dumb progressbar JFrame downloadFrame = new JFrame("Downloading"); { downloadFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); final JProgressBar dumJProgressBar = new JProgressBar(JProgressBar.HORIZONTAL); dumJProgressBar.setIndeterminate(true); downloadFrame.add(dumJProgressBar, BorderLayout.NORTH); downloadFrame.setSize(300, 60); } centerDefineFrame(downloadFrame, 300, 50); String archiveId = jtfDownloadField.getText().trim(); try { String vaultName = dlVault; FileDialog fd = new FileDialog(new Frame(), "Save Archive As...", FileDialog.SAVE); fd.setFile("Save Archive As..."); fd.setDirectory(System.getProperty("user.dir")); fd.setLocation(50, 50); fd.setVisible(true); String filePath = "" + fd.getDirectory() + System.getProperty("file.separator") + fd.getFile(); File outFile = new File(filePath); if (outFile != null) { downloadFrame.setTitle("Downloading " + outFile.toString()); downloadFrame.setVisible(true); Endpoints notificationEP = new Endpoints(locationChoice); AmazonSQSClient dlSQS = new AmazonSQSClient(dlCredentials); AmazonSNSClient dlSNS = new AmazonSNSClient(dlCredentials); dlSQS.setEndpoint(notificationEP.sqsEndpoint()); dlSNS.setEndpoint(notificationEP.snsEndpoint()); // ArchiveTransferManager atm = new // ArchiveTransferManager(dlClient, // dlCredentials); ArchiveTransferManager atm = new ArchiveTransferManager(dlClient, dlSQS, dlSNS); atm.download("-", vaultName, archiveId, outFile); JOptionPane.showMessageDialog(null, "Sucessfully downloaded " + outFile.toString(), "Success", JOptionPane.INFORMATION_MESSAGE); downloadFrame.setVisible(false); } } catch (AmazonServiceException k) { JOptionPane.showMessageDialog(null, "The server returned an error. Wait 24 hours after submitting an archive to attempt a download. Also check that correct location of archive has been set on the previous page.", "Error", JOptionPane.ERROR_MESSAGE); System.out.println("" + k); downloadFrame.setVisible(false); } catch (AmazonClientException i) { JOptionPane.showMessageDialog(null, "Client Error. Check that all fields are correct. Archive not downloaded.", "Error", JOptionPane.ERROR_MESSAGE); downloadFrame.setVisible(false); } catch (Exception j) { JOptionPane.showMessageDialog(null, "Archive not found. Unspecified Error.", "Error", JOptionPane.ERROR_MESSAGE); downloadFrame.setVisible(false); } return null; } }; downloadWorker.execute(); try { Thread.sleep(500); } catch (InterruptedException e1) { e1.printStackTrace(); } this.setVisible(false); dispose(); } } else if (e.getSource() == jbtBack) { this.setVisible(false); dispose(); } else { JOptionPane.showMessageDialog(this, "Please choose a valid action."); } }
From source file:com.github.abhinavmishra14.aws.glacier.service.impl.GlacierArchiveServiceImpl.java
License:Open Source License
@Override public UploadResult archive(final String vaultName, final InputStream inputStream, final String archiveDescription) throws AmazonServiceException, AmazonClientException, IOException { LOGGER.info("Uploading archive to vault: {} with archiveDescription: {}", vaultName, archiveDescription); File tempFile = null;/*from w ww.j a v a2 s .c o m*/ UploadResult uploadResult = null; try { // Create temporary file from stream to avoid 'out of memory' exception tempFile = AWSUtil.createTempFileFromStream(inputStream); final ArchiveTransferManager archiveTrMgr = new ArchiveTransferManager(glacierClient, sqsClient, snsClient); uploadResult = archiveTrMgr.upload(vaultName, archiveDescription, tempFile); } finally { AWSUtil.deleteTempFile(tempFile); // Delete the temporary file once uploaded } return uploadResult; }
From source file:com.github.abhinavmishra14.aws.glacier.service.impl.GlacierArchiveServiceImpl.java
License:Open Source License
@Override public UploadResult archive(final String vaultName, final File inputFile, final String archiveDescription) throws AmazonServiceException, AmazonClientException, FileNotFoundException { LOGGER.info("Uploading archive file: {} to vault: {} with archiveDescription: {}", inputFile.getAbsolutePath(), vaultName, archiveDescription); final ArchiveTransferManager archiveTrMgr = new ArchiveTransferManager(glacierClient, sqsClient, snsClient); return archiveTrMgr.upload(vaultName, archiveDescription, inputFile); }
From source file:com.leverno.ysbos.archive.example.ArchiveDownloadHighLevel.java
License:Open Source License
public static void main(String[] args) throws IOException { AWSCredentials credentials = getCredentials(); AmazonSQSClient sqs = new AmazonSQSClient(credentials); AmazonSNSClient sns = new AmazonSNSClient(credentials); glacier = new AmazonGlacierClient(credentials); glacier.setEndpoint(Constants.endpoint); sqs.setEndpoint(Constants.endpoint); sns.setEndpoint(Constants.endpoint); try {// ww w . j a v a 2 s .c o m ArchiveTransferManager atm = new ArchiveTransferManager(glacier, sqs, sns); atm.download(vaultName, archiveId, new File(downloadFilePath)); } catch (Exception e) { System.err.println(e); } }
From source file:de.kopis.glacier.commands.DownloadArchiveCommand.java
License:Open Source License
public void download(final String vaultName, final String archiveId, final File targetFile) { log.info("Downloading archive " + archiveId + " from vault " + vaultName + "..."); final ArchiveTransferManager atm = new ArchiveTransferManager(client, sqs, sns); atm.download(vaultName, archiveId, targetFile); log.info("Archive downloaded to " + targetFile); }
From source file:de.kopis.glacier.commands.UploadArchiveCommand.java
License:Open Source License
public void upload(final String vaultName, final File uploadFile) { log.info("Starting to upload " + uploadFile + " to vault " + vaultName + "..."); try {//from w w w .j av a 2s . c om final ArchiveTransferManager atm = new ArchiveTransferManager(client, sqs, sns); final String archiveId = atm.upload(vaultName, uploadFile.getName(), uploadFile).getArchiveId(); log.info("Uploaded archive " + archiveId); } catch (final IOException e) { log.error("Something went wrong while uploading " + uploadFile + vaultName + "to vault " + ".", e); } }
From source file:org.transitime.maintenance.AwsGlacier.java
License:Open Source License
/********************** Member Functions **************************/ public AwsGlacier(String region) { // Get credentials from credentials file, environment variable, or // Java property. // See http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/DefaultAWSCredentialsProviderChain.html AWSCredentialsProviderChain credentialsProvider = new DefaultAWSCredentialsProviderChain(); credentials = credentialsProvider.getCredentials(); logger.debug("Read in credentials AWSAccessKeyId={} AWSSecretKey={}...", credentials.getAWSAccessKeyId(), credentials.getAWSSecretKey().substring(0, 4)); // Create the glacier client and set to specified region. glacierClient = new AmazonGlacierClient(credentials); glacierClient.setEndpoint("https://glacier." + region + ".amazonaws.com"); // Set up params needed for retrieving vault inventory sqsClient = new AmazonSQSClient(credentials); sqsClient.setEndpoint("https://sqs." + region + ".amazonaws.com"); snsClient = new AmazonSNSClient(credentials); snsClient.setEndpoint("https://sns." + region + ".amazonaws.com"); // Create the ArchiveTransferManager used for uploading and // downloading files. Need to use ArchiveTransferManager constructor // that allows one to specify sqsClient & snsClient so that they have // the proper region. If use ArchiveTransferManager without specifying // sqs and sns clients then default ones are constructed, but these // use the default Virginia region, which is wrong. atm = new ArchiveTransferManager(glacierClient, sqsClient, snsClient); }