当前位置: 首页>>代码示例>>Java>>正文


Java FileDescriptor类代码示例

本文整理汇总了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);
    }
}
 
开发者ID:cuba-platform,项目名称:sampler,代码行数:23,代码来源:ImageEmbeddedFrame.java

示例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);
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:26,代码来源:WebFileUploadField.java

示例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;
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:21,代码来源:WebFileUploadField.java

示例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;
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:18,代码来源:DesktopFileUploadField.java

示例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);
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:29,代码来源:FileUploadController.java

示例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;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:18,代码来源:FileUploading.java

示例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);
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:19,代码来源:AmazonS3FileStorage.java

示例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);
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:17,代码来源:AmazonS3FileStorageTest.java

示例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));
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:29,代码来源:FileFrameController.java

示例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());
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:8,代码来源:FileDownloadController.java

示例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();
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:8,代码来源:AmazonS3FileStorage.java

示例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;
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:9,代码来源:WebFileUploadField.java

示例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;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:12,代码来源:WebFileDescriptorResource.java

示例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();
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:15,代码来源:AmazonS3FileStorage.java

示例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");
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:10,代码来源:FileLoaderClientImpl.java


注:本文中的com.haulmont.cuba.core.entity.FileDescriptor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。