本文整理汇总了Java中com.haulmont.cuba.core.entity.FileDescriptor类的典型用法代码示例。如果您正苦于以下问题:Java FileDescriptor类的具体用法?Java FileDescriptor怎么用?Java FileDescriptor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileDescriptor类属于com.haulmont.cuba.core.entity包,在下文中一共展示了FileDescriptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadImageFromFileStorage
import com.haulmont.cuba.core.entity.FileDescriptor; //导入依赖的package包/类
private void loadImageFromFileStorage() {
// A file descriptor entity is usually stored in the database and referenced by an attribute of your data
// model entity. Here we simply create it for the purpose of the example.
FileDescriptor imageFile = metadata.create(FileDescriptor.class);
imageFile.setId(UUID.fromString("61a6a1ee-f13a-f44f-0201-c2f9b3288305"));
imageFile.setName("platform-logo.png");
imageFile.setCreateDate(new Date(1427857200503L));
imageFile.setExtension("png");
byte[] bytes = null;
try {
bytes = fileStorageService.loadFile(imageFile);
} catch (FileStorageException e) {
showNotification("Unable to load image file", NotificationType.HUMANIZED);
}
if (bytes != null) {
imageFromFileStorage.setSource(imageFile.getName(), new ByteArrayInputStream(bytes));
imageFromFileStorage.setType(Embedded.Type.IMAGE);
} else {
imageFromFileStorage.setVisible(false);
}
}
示例2: initComponent
import com.haulmont.cuba.core.entity.FileDescriptor; //导入依赖的package包/类
protected void initComponent() {
component = new CubaFileUploadWrapper(uploadButton) {
@Override
protected void onSetInternalValue(Object newValue) {
internalValueChanged(newValue);
}
};
component.addFileNameClickListener(e -> {
FileDescriptor value = getValue();
if (value == null)
return;
switch (mode) {
case MANUAL:
String name = getFileName();
String fileName = StringUtils.isEmpty(name) ? value.getName() : name;
exportDisplay.show(this::getFileContent, fileName);
break;
case IMMEDIATE:
exportDisplay.show(value);
}
});
component.setClearButtonListener((Button.ClickListener) this::clearButtonClicked);
}
示例3: saveFile
import com.haulmont.cuba.core.entity.FileDescriptor; //导入依赖的package包/类
protected void saveFile(FileDescriptor fileDescriptor) {
switch (mode) {
case MANUAL:
internalValueChangedOnUpload = true;
setValue(fileDescriptor);
internalValueChangedOnUpload = false;
break;
case IMMEDIATE:
try {
fileUploading.putFileIntoStorage(fileId, fileDescriptor);
FileDescriptor commitedDescriptor = commitFileDescriptor(fileDescriptor);
setValue(commitedDescriptor);
} catch (FileStorageException e) {
log.error("Error has occurred during file saving", e);
}
break;
}
}
示例4: setValue
import com.haulmont.cuba.core.entity.FileDescriptor; //导入依赖的package包/类
@Override
public void setValue(Object value) {
DesktopBackgroundWorker.checkSwingUIAccess();
if (!Objects.equals(prevValue, value)) {
updateInstance(value);
updateComponent((FileDescriptor) value);
fireChangeListeners(value);
} else {
updateComponent(prevValue);
}
if (value == null || !PersistenceHelper.isNew(value)) {
fileId = null;
tempFileId = null;
}
}
示例5: uploadFile
import com.haulmont.cuba.core.entity.FileDescriptor; //导入依赖的package包/类
/**
* Method for simple file upload. File contents are placed in the request body. Optional file name parameter is
* passed as a query param.
*/
@PostMapping(consumes = "!multipart/form-data")
public ResponseEntity<FileInfo> uploadFile(HttpServletRequest request,
@RequestParam(required = false) String name) {
try {
String contentLength = request.getHeader("Content-Length");
long size = 0;
try {
size = Long.parseLong(contentLength);
} catch (NumberFormatException ignored) {
}
FileDescriptor fd = createFileDescriptor(name, size);
ServletInputStream is = request.getInputStream();
uploadToMiddleware(is, fd);
saveFileDescriptor(fd);
return createFileInfoResponseEntity(request, fd);
} catch (Exception e) {
log.error("File upload failed", e);
throw new RestAPIException("File upload failed", "File upload failed", HttpStatus.INTERNAL_SERVER_ERROR);
}
}
示例6: getFileDescriptor
import com.haulmont.cuba.core.entity.FileDescriptor; //导入依赖的package包/类
@Override
public FileDescriptor getFileDescriptor(UUID fileId, String name) {
File file = getFile(fileId);
if (file == null) {
return null;
}
Metadata metadata = AppBeans.get(Metadata.NAME);
FileDescriptor fDesc = metadata.create(FileDescriptor.class);
fDesc.setSize(file.length());
fDesc.setExtension(FilenameUtils.getExtension(name));
fDesc.setName(name);
fDesc.setCreateDate(timeSource.currentTimestamp());
return fDesc;
}
示例7: removeFile
import com.haulmont.cuba.core.entity.FileDescriptor; //导入依赖的package包/类
@Override
public void removeFile(FileDescriptor fileDescr) throws FileStorageException {
URL amazonUrl = getAmazonUrl(fileDescr);
// for a simple DELETE, we have no body so supply the precomputed 'empty' hash
Map<String, String> headers = new HashMap<>();
headers.put("x-amz-content-sha256", AWS4SignerBase.EMPTY_BODY_SHA256);
String authorization = createAuthorizationHeader(amazonUrl, "DELETE", headers);
headers.put("Authorization", authorization);
HttpUtils.HttpResponse httpResponse = HttpUtils.invokeHttpRequest(amazonUrl, "DELETE", headers, null);
if (!httpResponse.isStatusOk()) {
String message = String.format("Could not remove file %s. %s",
getFileName(fileDescr), getInputStreamContent(httpResponse));
throw new FileStorageException(FileStorageException.Type.IO_EXCEPTION, message);
}
}
示例8: setUp
import com.haulmont.cuba.core.entity.FileDescriptor; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
fileDescr = new FileDescriptor();
fileDescr.setCreateDate(new Date());
fileDescr.setSize((long) FILE_CONTENT.length());
fileDescr.setName("AmazonFileStorageTest");
fileDescr.setExtension("txt");
fileDescr2 = new FileDescriptor();
fileDescr2.setCreateDate(new Date());
fileDescr2.setSize((long) FILE_CONTENT.length());
fileDescr2.setName("AmazonFileStorageTest");
fileStorageAPI = new AmazonS3FileStorage();
fileStorageAPI.amazonS3Config = AppBeans.get(Configuration.class).getConfig(AmazonS3Config.class);
}
示例9: init
import com.haulmont.cuba.core.entity.FileDescriptor; //导入依赖的package包/类
@Override
public void init(Map<String, Object> params) {
super.init(params);
uploadField = (FileUploadField) getComponent("uploadField");
filesTable = (Table) getComponent("files");
initGeneratedColumn();
ds = (CollectionDatasource) getDsContext().get("filesDs");
Button remove = (Button) getComponentNN("remove");
remove.setAction(new RemoveAction(filesTable, false));
uploadField.addFileUploadSucceedListener(e -> {
fd = metadata.create(FileDescriptor.class);
fd.setName(uploadField.getFileName());
fd.setExtension(FilenameUtils.getExtension(uploadField.getFileName()));
FileUploadingAPI fileUploading = AppBeans.get(FileUploadingAPI.NAME);
File file = fileUploading.getFile(uploadField.getFileId());
fd.setSize(file.length());
fd.setCreateDate(AppBeans.get(TimeSource.class).currentTimestamp());
saveFile();
ds.addItem(fd);
showNotification(getMessage("uploadSuccess"), NotificationType.HUMANIZED);
});
uploadField.addFileUploadErrorListener(e -> showNotification(getMessage("uploadUnsuccess"), NotificationType.HUMANIZED));
}
示例10: getContentType
import com.haulmont.cuba.core.entity.FileDescriptor; //导入依赖的package包/类
protected String getContentType(FileDescriptor fd) {
if (StringUtils.isEmpty(fd.getExtension())) {
return FileTypesHelper.DEFAULT_MIME_TYPE;
}
return FileTypesHelper.getMIMEType("." + fd.getExtension().toLowerCase());
}
示例11: getFileName
import com.haulmont.cuba.core.entity.FileDescriptor; //导入依赖的package包/类
protected String getFileName(FileDescriptor fileDescriptor) {
if (StringUtils.isNotBlank(fileDescriptor.getExtension())) {
return fileDescriptor.getId().toString() + "." + fileDescriptor.getExtension();
} else {
return fileDescriptor.getId().toString();
}
}
示例12: getFileDescriptor
import com.haulmont.cuba.core.entity.FileDescriptor; //导入依赖的package包/类
@Override
public FileDescriptor getFileDescriptor() {
if (fileId != null) {
return fileUploading.getFileDescriptor(fileId, fileName);
} else {
return null;
}
}
示例13: setFileDescriptor
import com.haulmont.cuba.core.entity.FileDescriptor; //导入依赖的package包/类
@Override
public FileDescriptorResource setFileDescriptor(FileDescriptor fileDescriptor) {
Preconditions.checkNotNullArgument(fileDescriptor);
this.fileDescriptor = fileDescriptor;
hasSource = true;
fireResourceUpdateEvent();
return this;
}
示例14: fileExists
import com.haulmont.cuba.core.entity.FileDescriptor; //导入依赖的package包/类
@Override
public boolean fileExists(FileDescriptor fileDescr) {
URL amazonUrl = getAmazonUrl(fileDescr);
// for a simple HEAD, we have no body so supply the precomputed 'empty' hash
Map<String, String> headers = new HashMap<>();
headers.put("x-amz-content-sha256", AWS4SignerBase.EMPTY_BODY_SHA256);
String authorization = createAuthorizationHeader(amazonUrl, "HEAD", headers);
headers.put("Authorization", authorization);
HttpUtils.HttpResponse httpResponse = HttpUtils.invokeHttpRequest(amazonUrl, "HEAD", headers, null);
return httpResponse.isStatusOk();
}
示例15: saveStream
import com.haulmont.cuba.core.entity.FileDescriptor; //导入依赖的package包/类
@Override
public void saveStream(FileDescriptor fd, Supplier<InputStream> inputStreamSupplier) throws FileStorageException {
try {
saveStream(fd, inputStreamSupplier, null);
} catch (InterruptedException e) {
// should never happen
throw new RuntimeException("Interrupted exception on stream saving");
}
}