use of io.vertigo.dynamo.file.model.InputStreamBuilder in project vertigo by KleeGroup.
the class FileManagerTest method testCreateTempFileWithNoFileNoMime.
@Test
public void testCreateTempFileWithNoFileNoMime() {
final String fileName = "monTestFile.txt";
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, lastModified, length, inputStreamBuilder);
checkVFile(vFile, fileName, lastModified, "text/plain", length);
}
use of io.vertigo.dynamo.file.model.InputStreamBuilder in project vertigo by KleeGroup.
the class FileManagerImpl method createFile.
/**
* {@inheritDoc}
*/
@Override
public VFile createFile(final String fileName, final String typeMime, final URL resourceUrl) {
final long length;
final Instant lastModified;
try {
final URLConnection connection = resourceUrl.openConnection();
try {
length = connection.getContentLength();
lastModified = Instant.ofEpochMilli(connection.getLastModified());
} finally {
connection.getInputStream().close();
}
} catch (final IOException e) {
throw WrappedException.wrap(e, "Can't get file meta from url");
}
Assertion.checkArgument(length >= 0, "Can't get file meta from url");
final InputStreamBuilder inputStreamBuilder = resourceUrl::openStream;
return createFile(fileName, typeMime, lastModified, length, inputStreamBuilder);
}
Aggregations