use of io.vertigo.dynamo.file.model.InputStreamBuilder in project vertigo by KleeGroup.
the class FsFullFileStorePlugin method read.
/**
* {@inheritDoc}
*/
@Override
public FileInfo read(final FileInfoURI uri) {
/* read metadata*/
try {
final String metadataUri = obtainFullMetaDataFilePath(uri);
final Path metadataPath = Paths.get(metadataUri);
final List<String> infos = Files.readAllLines(metadataPath, Charset.forName(METADATA_CHARSET));
// récupération des infos
final String fileName = infos.get(0);
final String mimeType = infos.get(1);
final Instant lastModified = DateUtil.parseToInstant(infos.get(2), INFOS_DATE_PATTERN);
final Long length = Long.valueOf(infos.get(3));
final InputStreamBuilder inputStreamBuilder = new FileInputStreamBuilder(new File(obtainFullFilePath(uri)));
final VFile vFile = fileManager.createFile(fileName, mimeType, lastModified, length, inputStreamBuilder);
// retourne le fileinfo avec le fichier et son URI
final FsFileInfo fsFileInfo = new FsFileInfo(uri.getDefinition(), vFile);
fsFileInfo.setURIStored(uri);
return fsFileInfo;
} catch (final IOException e) {
throw WrappedException.wrap(e, "Can't read fileInfo " + uri.toURN());
}
}
use of io.vertigo.dynamo.file.model.InputStreamBuilder in project vertigo by KleeGroup.
the class DbFileStorePlugin method read.
/**
* {@inheritDoc}
*/
@Override
public FileInfo read(final FileInfoURI uri) {
Assertion.checkNotNull(uri);
checkDefinitionStoreBinding(uri.getDefinition());
// -----
final URI<Entity> dtoUri = new URI<>(storeDtDefinition, uri.getKey());
final Entity fileInfoDto = getStoreManager().getDataStore().readOne(dtoUri);
final InputStreamBuilder inputStreamBuilder = new DataStreamInputStreamBuilder(getValue(fileInfoDto, DtoFields.FILE_DATA, DataStream.class));
final String fileName = getValue(fileInfoDto, DtoFields.FILE_NAME, String.class);
final String mimeType = getValue(fileInfoDto, DtoFields.MIME_TYPE, String.class);
final Instant lastModified = getValue(fileInfoDto, DtoFields.LAST_MODIFIED, Instant.class);
final Long length = getValue(fileInfoDto, DtoFields.LENGTH, Long.class);
final VFile vFile = fileManager.createFile(fileName, mimeType, lastModified, length, inputStreamBuilder);
return new DatabaseFileInfo(uri.getDefinition(), vFile);
}
use of io.vertigo.dynamo.file.model.InputStreamBuilder in project vertigo by KleeGroup.
the class TwoTablesDbFileStorePlugin method read.
/**
* {@inheritDoc}
*/
@Override
public FileInfo read(final FileInfoURI fileInfoUri) {
checkDefinitionStoreBinding(fileInfoUri.getDefinition());
// Ramène FileMetada
final URI<Entity> dtoMetaDataUri = new URI<>(storeMetaDataDtDefinition, fileInfoUri.getKey());
final DtObject fileMetadataDto = getStoreManager().getDataStore().readOne(dtoMetaDataUri);
final Object fdtId = getValue(fileMetadataDto, DtoFields.FDT_ID, Object.class);
// Ramène FileData
final URI<Entity> dtoDataUri = new URI<>(storeFileDtDefinition, fdtId);
final DtObject fileDataDto = getStoreManager().getDataStore().readOne(dtoDataUri);
// Construction du vFile.
final InputStreamBuilder inputStreamBuilder = new DataStreamInputStreamBuilder(getValue(fileDataDto, DtoFields.FILE_DATA, DataStream.class));
final String fileName = getValue(fileMetadataDto, DtoFields.FILE_NAME, String.class);
final String mimeType = getValue(fileMetadataDto, DtoFields.MIME_TYPE, String.class);
final Instant lastModified = getValue(fileMetadataDto, DtoFields.LAST_MODIFIED, Instant.class);
final Long length = getValue(fileMetadataDto, DtoFields.LENGTH, Long.class);
final VFile vFile = fileManager.createFile(fileName, mimeType, lastModified, length, inputStreamBuilder);
// TODO passer par une factory de FileInfo à partir de la FileInfoDefinition (comme DomainFactory)
final FileInfo fileInfo = new DatabaseFileInfo(fileInfoUri.getDefinition(), vFile);
fileInfo.setURIStored(fileInfoUri);
return fileInfo;
}
use of io.vertigo.dynamo.file.model.InputStreamBuilder in project vertigo by KleeGroup.
the class FsFileStorePlugin method read.
/**
* {@inheritDoc}
*/
@Override
public FileInfo read(final FileInfoURI uri) {
// récupération de l'objet en base
final URI<Entity> dtoUri = createDtObjectURI(uri);
final DtObject fileInfoDto = getStoreManager().getDataStore().readOne(dtoUri);
// récupération du fichier
final String fileName = getValue(fileInfoDto, DtoFields.FILE_NAME, String.class);
final String mimeType = getValue(fileInfoDto, DtoFields.MIME_TYPE, String.class);
final Instant lastModified = getValue(fileInfoDto, DtoFields.LAST_MODIFIED, Instant.class);
final Long length = getValue(fileInfoDto, DtoFields.LENGTH, Long.class);
final String filePath = getValue(fileInfoDto, DtoFields.FILE_PATH, String.class);
final InputStreamBuilder inputStreamBuilder = new FileInputStreamBuilder(new File(documentRoot + filePath));
final VFile vFile = fileManager.createFile(fileName, mimeType, lastModified, length, inputStreamBuilder);
// retourne le fileinfo avec le fichier et son URI
final FsFileInfo fsFileInfo = new FsFileInfo(uri.getDefinition(), vFile);
fsFileInfo.setURIStored(uri);
return fsFileInfo;
}
use of io.vertigo.dynamo.file.model.InputStreamBuilder in project vertigo by KleeGroup.
the class FileManagerTest method testCreateTempFileWithNoFile.
@Test
public void testCreateTempFileWithNoFile() {
final String fileName = "monTestFile.txt";
final String typeMime = "monTypeMime";
final Instant lastModified = Instant.now();
final long length = 123;
final InputStreamBuilder inputStreamBuilder = new InputStreamBuilder() {
@Override
public InputStream createInputStream() {
return new StringBufferInputStream("Contenu test");
}
};
final VFile vFile = fileManager.createFile(fileName, typeMime, lastModified, length, inputStreamBuilder);
checkVFile(vFile, fileName, lastModified, typeMime, length);
}
Aggregations