Search in sources :

Example 1 with RemoteFile

use of org.eclipse.scout.rt.shared.services.common.file.RemoteFile in project scout.rt by eclipse.

the class AbstractHolidayItemProvider method execLoadItemsInBackground.

@Override
protected void execLoadItemsInBackground(IClientSession session, Date minDate, Date maxDate, final Set<ICalendarItem> result) {
    IHolidayCalendarService service = BEANS.get(IHolidayCalendarService.class);
    if (service != null) {
        RemoteFile f = new RemoteFile(getConfiguredRemoteFile(), 0);
        result.addAll(service.getItems(f, minDate, maxDate));
    }
}
Also used : IHolidayCalendarService(org.eclipse.scout.rt.shared.services.common.calendar.IHolidayCalendarService) RemoteFile(org.eclipse.scout.rt.shared.services.common.file.RemoteFile)

Example 2 with RemoteFile

use of org.eclipse.scout.rt.shared.services.common.file.RemoteFile in project scout.rt by eclipse.

the class RemoteFileService method putRemoteFile.

@Override
@RemoteServiceAccessDenied
@SuppressWarnings("findbugs:RV_RETURN_VALUE_IGNORED_BAD_PRACTICE")
public void putRemoteFile(RemoteFile spec) {
    File file = getFileInternal(spec);
    file.getParentFile().mkdirs();
    try (FileOutputStream out = new FileOutputStream(file)) {
        spec.writeData(out);
        file.setLastModified(file.lastModified());
    } catch (Exception e) {
        throw new ProcessingException("error writing file: " + file.getAbsoluteFile(), e);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) File(java.io.File) RemoteFile(org.eclipse.scout.rt.shared.services.common.file.RemoteFile) IOException(java.io.IOException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) RemoteServiceAccessDenied(org.eclipse.scout.rt.shared.servicetunnel.RemoteServiceAccessDenied)

Example 3 with RemoteFile

use of org.eclipse.scout.rt.shared.services.common.file.RemoteFile in project scout.rt by eclipse.

the class RemoteFileService method getRemoteFileInternal.

private RemoteFile getRemoteFileInternal(RemoteFile spec, boolean includeContent, long startPosition, long maxBlockSize) {
    File file = getFileInternal(spec);
    RemoteFile result = new RemoteFile(spec.getDirectory(), file.getName(), spec.getLocale(), -1, spec.getCharsetName());
    result.setContentType(spec.getContentType());
    if (!StringUtility.hasText(result.getContentType())) {
        int pos = result.getName().lastIndexOf('.');
        String ext = "";
        if (pos >= 0) {
            ext = result.getName().substring(pos + 1);
        }
        result.setContentTypeByExtension(ext);
    }
    // 
    if (file.exists()) {
        result.setExists(true);
        result.setLastModified(file.lastModified());
        long partLength = file.length();
        if (maxBlockSize > -1 && partLength > maxBlockSize) {
            partLength = partLength - startPosition;
            if (partLength > maxBlockSize) {
                partLength = maxBlockSize;
            }
            if (partLength <= 0) {
                partLength = 0;
            }
        }
        result.setContentLength((int) partLength);
        if (!includeContent) {
        // no content requested
        } else if (ObjectUtility.equals(spec.getName(), result.getName()) && result.getLastModified() <= spec.getLastModified() && result.getPartStartPosition() == spec.getPartStartPosition()) {
        // no content change, keep null
        } else {
            try (InputStream in = new FileInputStream(file)) {
                result.readData(in, startPosition, maxBlockSize);
            } catch (IOException e) {
                throw new ProcessingException("error reading file: " + file.getAbsolutePath(), e);
            }
        }
    }
    return result;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) File(java.io.File) RemoteFile(org.eclipse.scout.rt.shared.services.common.file.RemoteFile) RemoteFile(org.eclipse.scout.rt.shared.services.common.file.RemoteFile) FileInputStream(java.io.FileInputStream) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 4 with RemoteFile

use of org.eclipse.scout.rt.shared.services.common.file.RemoteFile in project scout.rt by eclipse.

the class RemoteFileService method getRemoteFiles.

public RemoteFile[] getRemoteFiles(String folderPath, FilenameFilter filter, RemoteFile[] existingFileInfoOnClient, String charsetName, long maxBlockSize) {
    HashMap<String, RemoteFile> fileList = new HashMap<String, RemoteFile>();
    if (existingFileInfoOnClient != null) {
        for (RemoteFile rf : existingFileInfoOnClient) {
            fileList.put((rf.getDirectory().endsWith("/") ? rf.getDirectory() : rf.getDirectory() + "/") + rf.getName(), rf);
        }
    }
    String[][] files = getFiles(folderPath, filter);
    for (String[] file : files) {
        if (!fileList.containsKey((file[0].endsWith("/") ? file[0] : file[0] + "/") + file[1])) {
            fileList.put((file[0].endsWith("/") ? file[0] : file[0] + "/") + file[1], new RemoteFile(file[0], file[1], 0L, charsetName));
        }
    }
    RemoteFile[] retVal = new RemoteFile[fileList.size()];
    int i = 0;
    for (RemoteFile rf : fileList.values()) {
        retVal[i] = getRemoteFile(rf, maxBlockSize);
        i++;
    }
    return retVal;
}
Also used : HashMap(java.util.HashMap) RemoteFile(org.eclipse.scout.rt.shared.services.common.file.RemoteFile)

Example 5 with RemoteFile

use of org.eclipse.scout.rt.shared.services.common.file.RemoteFile in project scout.rt by eclipse.

the class FileSystemBookmarkStorageService method writeBookmarkFolder.

/**
 * Writes a bookmark folder.
 *
 * @since 3.8.2
 */
private void writeBookmarkFolder(BookmarkFolder folder, String filename, Permission permission) {
    try {
        if (ACCESS.check(permission)) {
            byte[] bytes = SerializationUtility.createObjectSerializer().serialize(folder);
            // 
            RemoteFile spec = new RemoteFile("bookmarks", filename, 0);
            spec.readData(new ByteArrayInputStream(bytes));
            BEANS.get(IRemoteFileService.class).putRemoteFile(spec);
        }
    } catch (IOException e) {
        throw new ProcessingException("", e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) RemoteFile(org.eclipse.scout.rt.shared.services.common.file.RemoteFile) IRemoteFileService(org.eclipse.scout.rt.shared.services.common.file.IRemoteFileService) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Aggregations

RemoteFile (org.eclipse.scout.rt.shared.services.common.file.RemoteFile)14 IOException (java.io.IOException)9 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)9 File (java.io.File)7 IRemoteFileService (org.eclipse.scout.rt.shared.services.common.file.IRemoteFileService)7 FileInputStream (java.io.FileInputStream)3 FileOutputStream (java.io.FileOutputStream)3 BufferedInputStream (java.io.BufferedInputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 X509Certificate (java.security.cert.X509Certificate)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FilenameFilter (java.io.FilenameFilter)1 GeneralSecurityException (java.security.GeneralSecurityException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 CertificateException (java.security.cert.CertificateException)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1