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));
}
}
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);
}
}
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;
}
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;
}
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);
}
}
Aggregations