use of com.microsoft.tooling.msservices.model.storage.BlobItem in project azure-tools-for-java by Microsoft.
the class BlobExplorerFileEditor method uploadFile.
private void uploadFile(final String path, final File selectedFile) {
Job job = new Job("Uploading blob...") {
@Override
protected IStatus run(final IProgressMonitor monitor) {
monitor.beginTask("Uploading blob...", IProgressMonitor.UNKNOWN);
try {
final BlobDirectory blobDirectory = directoryQueue.peekLast();
final BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(selectedFile));
monitor.subTask("0% uploaded");
try {
final CallableSingleArg<Void, Long> callable = new CallableSingleArg<Void, Long>() {
@Override
public Void call(Long uploadedBytes) throws Exception {
double progress = ((double) uploadedBytes) / selectedFile.length();
monitor.worked((int) (100 * progress));
monitor.subTask(String.format("%s%% uploaded", (int) (progress * 100)));
return null;
}
};
try {
StorageClientSDKManager.getManager().uploadBlobFileContent(connectionString, blobContainer, path, bufferedInputStream, callable, 1024 * 1024, selectedFile.length());
} catch (AzureCmdException e) {
e.printStackTrace();
} finally {
try {
bufferedInputStream.close();
} catch (IOException ignored) {
}
}
if (monitor.isCanceled()) {
// future.cancel(true);
bufferedInputStream.close();
for (BlobItem blobItem : StorageClientSDKManager.getManager().getBlobItems(connectionString, blobDirectory)) {
if (blobItem instanceof BlobFile && blobItem.getPath().equals(path)) {
StorageClientSDKManager.getManager().deleteBlobFile(connectionString, (BlobFile) blobItem);
}
}
}
try {
directoryQueue.clear();
directoryQueue.addLast(StorageClientSDKManager.getManager().getRootDirectory(connectionString, blobContainer));
for (String pathDir : path.split("/")) {
for (BlobItem blobItem : StorageClientSDKManager.getManager().getBlobItems(connectionString, directoryQueue.getLast())) {
if (blobItem instanceof BlobDirectory && blobItem.getName().equals(pathDir)) {
directoryQueue.addLast((BlobDirectory) blobItem);
}
}
}
} catch (AzureCmdException e) {
DefaultLoader.getUIHelper().showException("Error showing new blob", e, "Error showing new blob", false, true);
}
DefaultLoader.getIdeHelper().invokeLater(new Runnable() {
@Override
public void run() {
fillGrid();
}
});
} catch (Exception e) {
Throwable connectionFault = e.getCause();
Throwable realFault = null;
if (connectionFault != null) {
realFault = connectionFault.getCause();
}
monitor.setTaskName("Error uploading Blob");
String message = realFault == null ? null : realFault.getMessage();
if (connectionFault != null && message == null) {
message = "Error type " + connectionFault.getClass().getName();
}
monitor.subTask((connectionFault instanceof SocketTimeoutException) ? "Connection timed out" : message);
}
} catch (Exception e) {
DefaultLoader.getUIHelper().showException("Error uploading Blob", e, "Error uploading Blob", false, true);
return Status.CANCEL_STATUS;
} finally {
monitor.done();
}
return Status.OK_STATUS;
}
};
job.schedule();
}
use of com.microsoft.tooling.msservices.model.storage.BlobItem 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.BlobItem in project azure-tools-for-java by Microsoft.
the class BlobExplorerFileEditor method fillGrid.
public void fillGrid() {
setUIState(true);
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Loading blobs...", false) {
@Override
public void run(@NotNull ProgressIndicator progressIndicator) {
try {
progressIndicator.setIndeterminate(true);
if (directoryQueue.peekLast() == null) {
directoryQueue.addLast(StorageClientSDKManager.getManager().getRootDirectory(connectionString, blobContainer));
}
blobItems = StorageClientSDKManager.getManager().getBlobItems(connectionString, directoryQueue.peekLast());
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);
}
}
}
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
pathLabel.setText(directoryQueue.peekLast().getPath());
DefaultTableModel model = (DefaultTableModel) blobListTable.getModel();
while (model.getRowCount() > 0) {
model.removeRow(0);
}
for (BlobItem blobItem : blobItems) {
if (blobItem instanceof BlobDirectory) {
model.addRow(new Object[] { UIHelperImpl.loadIcon("storagefolder.png"), blobItem.getName(), "", "", "", blobItem.getUri() });
} else {
BlobFile blobFile = (BlobFile) blobItem;
model.addRow(new String[] { "", blobFile.getName(), UIHelperImpl.readableFileSize(blobFile.getSize()), new SimpleDateFormat().format(blobFile.getLastModified().getTime()), blobFile.getContentType(), blobFile.getUri() });
}
}
setUIState(false);
blobListTable.clearSelection();
}
});
} catch (AzureCmdException ex) {
String msg = "An error occurred while attempting to query blob list." + "\n" + String.format(message("webappExpMsg"), ex.getMessage());
PluginUtil.displayErrorDialogAndLog(message("errTtl"), msg, ex);
}
}
});
}
use of com.microsoft.tooling.msservices.model.storage.BlobItem in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method getBlobItems.
@NotNull
public List<BlobItem> getBlobItems(@NotNull String connectionString, @NotNull BlobDirectory blobDirectory) throws AzureCmdException {
List<BlobItem> biList = new ArrayList<BlobItem>();
try {
CloudBlobClient client = getCloudBlobClient(connectionString);
String containerName = blobDirectory.getContainerName();
String delimiter = client.getDirectoryDelimiter();
CloudBlobContainer container = client.getContainerReference(containerName);
CloudBlobDirectory directory = container.getDirectoryReference(blobDirectory.getPath());
for (ListBlobItem item : directory.listBlobs()) {
String uri = item.getUri() != null ? item.getUri().toString() : "";
if (item instanceof CloudBlobDirectory) {
CloudBlobDirectory subDirectory = (CloudBlobDirectory) item;
String name = extractBlobItemName(subDirectory.getPrefix(), delimiter);
String path = Strings.nullToEmpty(subDirectory.getPrefix());
biList.add(new BlobDirectory(name, uri, containerName, path));
} else if (item instanceof CloudBlob) {
CloudBlob blob = (CloudBlob) item;
String name = extractBlobItemName(blob.getName(), delimiter);
String path = Strings.nullToEmpty(blob.getName());
String type = "";
String cacheControlHeader = "";
String contentEncoding = "";
String contentLanguage = "";
String contentType = "";
String contentMD5Header = "";
String eTag = "";
Calendar lastModified = new GregorianCalendar();
long size = 0;
BlobProperties properties = blob.getProperties();
if (properties != null) {
if (properties.getBlobType() != null) {
type = properties.getBlobType().toString();
}
cacheControlHeader = Strings.nullToEmpty(properties.getCacheControl());
contentEncoding = Strings.nullToEmpty(properties.getContentEncoding());
contentLanguage = Strings.nullToEmpty(properties.getContentLanguage());
contentType = Strings.nullToEmpty(properties.getContentType());
contentMD5Header = Strings.nullToEmpty(properties.getContentMD5());
eTag = Strings.nullToEmpty(properties.getEtag());
if (properties.getLastModified() != null) {
lastModified.setTime(properties.getLastModified());
}
size = properties.getLength();
}
biList.add(new BlobFile(name, uri, containerName, path, type, cacheControlHeader, contentEncoding, contentLanguage, contentType, contentMD5Header, eTag, lastModified, size));
}
}
return biList;
} catch (Throwable t) {
throw new AzureCmdException("Error retrieving the Blob Item list", t);
}
}
Aggregations