use of com.bluenimble.platform.storage.StorageException in project serverless by bluenimble.
the class FileSystemFolder method add.
@Override
public StorageObject add(ApiStreamSource ss, String altName, boolean overwrite) throws StorageException {
if (Lang.isNullOrEmpty(altName) && ss == null) {
throw new StorageException("object name is required");
}
String name = altName != null ? altName : ss.name();
validateName(name);
File file = new File(source, name);
if (file.exists() && !overwrite) {
throw new StorageException("object '" + name + "' already exists under " + name());
}
if (ss == null && !file.exists()) {
try {
file.createNewFile();
} catch (IOException ioex) {
throw new StorageException(ioex.getMessage(), ioex);
}
return new FileSystemStorageObject(file, false);
}
OutputStream os = null;
try {
os = new FileOutputStream(file);
IOUtils.copy(ss.stream(), os);
} catch (IOException ioex) {
throw new StorageException(ioex.getMessage(), ioex);
} finally {
IOUtils.closeQuietly(os);
}
return new FileSystemStorageObject(file, false);
}
use of com.bluenimble.platform.storage.StorageException in project serverless by bluenimble.
the class FileSystemFolder method get.
@Override
public StorageObject get(String path) throws StorageException {
validatePath(path);
File file = new File(source, path);
if (!file.exists()) {
throw new StorageException("object '" + path + "' not found under " + name());
}
if (file.isDirectory()) {
return new FileSystemFolder(file, false);
}
return new FileSystemStorageObject(file, false);
}
use of com.bluenimble.platform.storage.StorageException in project serverless by bluenimble.
the class FileSystemFolder method add.
@Override
public Folder add(String path, boolean ignoreIfExists) throws StorageException {
validatePath(path);
File folder = new File(source, path);
if (folder.exists() && !ignoreIfExists) {
throw new StorageException("folder '" + path + "' already exists under " + name());
}
folder.mkdirs();
if (!folder.exists()) {
throw new StorageException("unbale to create folder '" + path + "' under " + name());
}
return new FileSystemFolder(folder, false);
}
use of com.bluenimble.platform.storage.StorageException in project serverless by bluenimble.
the class FileSystemStorageObject method writer.
@Override
public OutputStream writer(ApiContext context) throws StorageException {
if (isFolder()) {
throw new StorageException(name() + " is a folder");
}
OutputStream os = null;
try {
os = new FileOutputStream(source);
} catch (IOException ioex) {
throw new StorageException(ioex.getMessage(), ioex);
}
RecyclableOutputStream ros = new RecyclableOutputStream(os);
context.addRecyclable(Lang.UUID(10), ros);
return ros;
}
use of com.bluenimble.platform.storage.StorageException in project serverless by bluenimble.
the class FileSystemStorageObject method reader.
@Override
public InputStream reader(ApiContext context) throws StorageException {
if (isFolder()) {
throw new StorageException(name() + " is a folder");
}
InputStream is = null;
try {
is = new FileInputStream(source);
} catch (IOException ioex) {
throw new StorageException(ioex.getMessage(), ioex);
}
RecyclableInputStream ris = new RecyclableInputStream(is);
context.addRecyclable(Lang.UUID(10), ris);
return ris;
}
Aggregations