use of com.microsoft.tooling.msservices.model.storage.BlobFile in project azure-tools-for-java by Microsoft.
the class BlobExplorerFileEditor method fillGrid.
public void fillGrid() {
setUIState(true);
DefaultLoader.getIdeHelper().runInBackground(null, "Loading blobs...", false, true, "Loading blobs...", new Runnable() {
@Override
public void run() {
try {
if (directoryQueue.peekLast() == null) {
directoryQueue.addLast(StorageClientSDKManager.getManager().getRootDirectory(connectionString, blobContainer));
}
blobItems = StorageClientSDKManager.getManager().getBlobItems(connectionString, directoryQueue.peekLast());
DefaultLoader.getIdeHelper().invokeLater(new Runnable() {
@Override
public void run() {
if (!queryTextField.getText().isEmpty()) {
for (int i = blobItems.size() - 1; i >= 0; i--) {
BlobItem blobItem = blobItems.get(i);
if (blobItem instanceof BlobFile && !blobItem.getName().startsWith(queryTextField.getText())) {
blobItems.remove(i);
}
}
}
pathLabel.setText(directoryQueue.peekLast().getPath());
tableViewer.setInput(blobItems);
tableViewer.refresh();
setUIState(false);
//
// blobListTable.clearSelection();
}
});
} catch (AzureCmdException ex) {
DefaultLoader.getUIHelper().showException("Error querying blob list.", ex, "Error querying blobs", false, true);
}
}
});
}
use of com.microsoft.tooling.msservices.model.storage.BlobFile in project azure-tools-for-java by Microsoft.
the class BlobExplorerFileEditor method downloadSelectedFile.
private void downloadSelectedFile(final File targetFile, final boolean open) {
final BlobFile fileSelection = getFileSelection();
if (fileSelection != null) {
Job job = new Job("Downloading blob...") {
@Override
protected IStatus run(final IProgressMonitor monitor) {
monitor.beginTask("Downloading blob...", IProgressMonitor.UNKNOWN);
try {
if (!targetFile.exists()) {
if (!targetFile.createNewFile()) {
throw new IOException("File not created");
}
}
final BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(targetFile), 65536) {
private long runningCount = 0;
@Override
public synchronized void write(@NotNull byte[] bytes, int i, int i1) throws IOException {
super.write(bytes, i, i1);
runningCount += i1;
double progress = (double) runningCount / fileSelection.getSize();
monitor.worked((int) (100 * progress));
monitor.subTask(String.format("%s%% downloaded", (int) (progress * 100)));
}
};
try {
// public void run() {
try {
StorageClientSDKManager.getManager().downloadBlobFileContent(connectionString, fileSelection, bufferedOutputStream);
if (open && targetFile.exists()) {
try {
final Process p;
Runtime runtime = Runtime.getRuntime();
p = runtime.exec(new String[] { "open", "-R", targetFile.getName() }, null, targetFile.getParentFile());
InputStream errorStream = p.getErrorStream();
String errResponse = new String(IOUtils.readFully(errorStream, -1, true));
if (p.waitFor() != 0) {
throw new Exception(errResponse);
}
} catch (Exception e) {
monitor.setTaskName("Error opening file");
monitor.subTask(e.getMessage());
}
// Desktop.getDesktop().open(targetFile);
}
} catch (AzureCmdException e) {
Throwable connectionFault = e.getCause().getCause();
monitor.setTaskName("Error downloading Blob");
monitor.subTask((connectionFault instanceof SocketTimeoutException) ? "Connection timed out" : connectionFault.getMessage());
return Status.CANCEL_STATUS;
}
} finally {
bufferedOutputStream.close();
}
} catch (IOException e) {
DefaultLoader.getUIHelper().showException("Error downloading Blob", e, "Error downloading Blob", false, true);
return Status.CANCEL_STATUS;
} finally {
monitor.done();
}
return Status.OK_STATUS;
}
};
job.schedule();
}
}
use of com.microsoft.tooling.msservices.model.storage.BlobFile in project azure-tools-for-java by Microsoft.
the class BlobExplorerFileEditor method saveAsSelectedFile.
private void saveAsSelectedFile() {
BlobFile fileSelection = getFileSelection();
assert fileSelection != null;
File file = DefaultLoader.getUIHelper().showFileChooser("Save As");
if (file != null) {
downloadSelectedFile(file, false);
}
}
use of com.microsoft.tooling.msservices.model.storage.BlobFile in project azure-tools-for-java by Microsoft.
the class BlobExplorerFileEditor method downloadSelectedFile.
private void downloadSelectedFile(final File targetFile, final boolean open) {
final BlobFile fileSelection = getFileSelection();
if (fileSelection != null) {
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Downloading blob...", true) {
@Override
public void run(@NotNull final ProgressIndicator progressIndicator) {
try {
progressIndicator.setIndeterminate(false);
if (!targetFile.exists()) {
if (!targetFile.createNewFile()) {
throw new IOException("File not created");
}
}
final BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(targetFile), 65536) {
private long runningCount = 0;
@Override
public synchronized void write(@NotNull byte[] bytes, int i, int i1) throws IOException {
super.write(bytes, i, i1);
runningCount += i1;
double progress = (double) runningCount / fileSelection.getSize();
progressIndicator.setFraction(progress);
progressIndicator.setText2(String.format("%s%% downloaded", (int) (progress * 100)));
}
};
try {
Future<?> future = ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
@Override
public void run() {
try {
StorageClientSDKManager.getManager().downloadBlobFileContent(connectionString, fileSelection, bufferedOutputStream);
if (open && targetFile.exists()) {
Desktop.getDesktop().open(targetFile);
}
} catch (AzureCmdException e) {
Throwable connectionFault = e.getCause().getCause();
progressIndicator.setText("Error downloading Blob");
progressIndicator.setText2((connectionFault instanceof SocketTimeoutException) ? "Connection timed out" : connectionFault.getMessage());
} catch (IOException ex) {
try {
final Process p;
Runtime runtime = Runtime.getRuntime();
p = runtime.exec(new String[] { "open", "-R", targetFile.getName() }, null, targetFile.getParentFile());
InputStream errorStream = p.getErrorStream();
String errResponse = new String(IOUtils.readFully(errorStream, -1, true));
if (p.waitFor() != 0) {
throw new Exception(errResponse);
}
} catch (Exception e) {
progressIndicator.setText("Error openning file");
progressIndicator.setText2(ex.getMessage());
}
}
}
});
while (!future.isDone()) {
progressIndicator.checkCanceled();
if (progressIndicator.isCanceled()) {
future.cancel(true);
}
}
} finally {
bufferedOutputStream.close();
}
} catch (IOException e) {
PluginUtil.displayErrorDialogAndLog(message("errTtl"), "An error occurred while attempting to download Blob.", e);
}
}
});
}
}
use of com.microsoft.tooling.msservices.model.storage.BlobFile in project azure-tools-for-java by Microsoft.
the class BlobExplorerFileEditor method copyURLSelectedFile.
private void copyURLSelectedFile() {
BlobFile fileSelection = getFileSelection();
if (fileSelection != null) {
StringSelection selection = new StringSelection(fileSelection.getUri());
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, selection);
}
}
Aggregations