Search in sources :

Example 1 with TempFile

use of io.vertigo.util.TempFile in project vertigo by KleeGroup.

the class TestUtil method createVFile.

/**
 * Crée un VFile relativement d'un class de base.
 * @param fileName Nom/path du fichier
 * @param baseClass Class de base pour le chemin relatif
 * @return VFile
 */
public static VFile createVFile(final FileManager fileManager, final String fileName, final Class<?> baseClass) {
    try {
        try (final InputStream in = baseClass.getResourceAsStream(fileName)) {
            Assertion.checkNotNull(in, "fichier non trouvé : {0}", fileName);
            final File file = new TempFile("tmp", '.' + FileUtil.getFileExtension(fileName));
            FileUtil.copy(in, file);
            return fileManager.createFile(file);
        }
    } catch (final IOException e) {
        throw WrappedException.wrap(e);
    }
}
Also used : TempFile(io.vertigo.util.TempFile) InputStream(java.io.InputStream) IOException(java.io.IOException) TempFile(io.vertigo.util.TempFile) VFile(io.vertigo.dynamo.file.model.VFile) File(java.io.File)

Example 2 with TempFile

use of io.vertigo.util.TempFile in project vertigo by KleeGroup.

the class SqlDataStreamMappingUtil method createDataStream.

private static DataStream createDataStream(final InputStream in, final byte[] bytes) throws IOException, SqlOffLimitsException {
    // On crée  un fichier temporaire.
    final File tmpFile = new TempFile("kdata", ".tmp");
    // 1ere étape : on recopie le contenu de la mémoire dans le fichier. (car on ne peut pas relire le Blob)
    try (final OutputStream fileOut = new FileOutputStream(tmpFile);
        final InputStream memoryIn = new ByteArrayInputStream(bytes)) {
        copy(memoryIn, fileOut, FILE_MAX_LENGTH);
        Assertion.checkState(tmpFile.length() <= MEMORY_MAX_LENTH, "Le fichier n'a pas repris le debut de l'export (RAM)");
        // 2eme Etape : on copie la suite
        final long length = copy(in, fileOut, FILE_MAX_LENGTH);
        // La longueur totale du fichier est la somme.
        return new FileDataStream(tmpFile, length + bytes.length);
    }
}
Also used : TempFile(io.vertigo.util.TempFile) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) TempFile(io.vertigo.util.TempFile)

Aggregations

TempFile (io.vertigo.util.TempFile)2 File (java.io.File)2 InputStream (java.io.InputStream)2 VFile (io.vertigo.dynamo.file.model.VFile)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1