Search in sources :

Example 1 with File

use of com.github.mgramin.sqlboot.tools.files.file.File in project sql-boot by sql-boot.

the class ZippedFile method unzip.

private byte[] unzip() throws BootException {
    try (ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        ZipOutputStream zip = new ZipOutputStream(bytes)) {
        for (final File ent : this.origins) {
            zip.putNextEntry(new ZipEntry(ent.name()));
            zip.write(ent.content());
            zip.closeEntry();
        }
        zip.close();
        bytes.close();
        return bytes.toByteArray();
    } catch (final IOException exception) {
        throw new BootException(exception);
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) BootException(com.github.mgramin.sqlboot.exceptions.BootException) File(com.github.mgramin.sqlboot.tools.files.file.File)

Example 2 with File

use of com.github.mgramin.sqlboot.tools.files.file.File in project sql-boot by sql-boot.

the class LocalFileSystem method listFiles.

@Override
public List<File> listFiles(final String mask) {
    try {
        DirectoryScanner scanner = new DirectoryScanner();
        scanner.setIncludes(new String[] { mask });
        scanner.setBasedir(this.basedir.replace("\\", "/"));
        scanner.setCaseSensitive(false);
        scanner.scan();
        String[] files = scanner.getIncludedFiles();
        List<File> result = new ArrayList<>();
        for (String file : files) {
            result.add(new SimpleFile(file, FileUtils.readFileToByteArray(new java.io.File(basedir + "/" + file))));
        }
        return result;
    } catch (IOException exception) {
        throw new BootException(exception);
    }
}
Also used : DirectoryScanner(org.apache.tools.ant.DirectoryScanner) ArrayList(java.util.ArrayList) SimpleFile(com.github.mgramin.sqlboot.tools.files.file.impl.SimpleFile) IOException(java.io.IOException) BootException(com.github.mgramin.sqlboot.exceptions.BootException) File(com.github.mgramin.sqlboot.tools.files.file.File) SimpleFile(com.github.mgramin.sqlboot.tools.files.file.impl.SimpleFile)

Example 3 with File

use of com.github.mgramin.sqlboot.tools.files.file.File in project sql-boot by sql-boot.

the class ZippedFileTest method content.

@Test
public void content() throws Exception {
    File zip = new ZippedFile("test.zip", asList(new FakeFile()));
    assertEquals(144, zip.content().length);
}
Also used : FakeFile(com.github.mgramin.sqlboot.tools.files.file.impl.FakeFile) FakeFile(com.github.mgramin.sqlboot.tools.files.file.impl.FakeFile) File(com.github.mgramin.sqlboot.tools.files.file.File) Test(org.junit.Test)

Aggregations

File (com.github.mgramin.sqlboot.tools.files.file.File)3 BootException (com.github.mgramin.sqlboot.exceptions.BootException)2 IOException (java.io.IOException)2 FakeFile (com.github.mgramin.sqlboot.tools.files.file.impl.FakeFile)1 SimpleFile (com.github.mgramin.sqlboot.tools.files.file.impl.SimpleFile)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)1 Test (org.junit.Test)1