Search in sources :

Example 1 with FileUtility

use of org.onebusaway.util.FileUtility in project onebusaway-application-modules by camsys.

the class DirectoryStagingBundleSource method stage.

@Override
public void stage(String env, String bundleDir, String bundleName) throws Exception {
    File srcDir = new File(this.getMasterBundleDirectory().toString() + File.separator + bundleDir + File.separator + "builds" + File.separator + bundleName);
    File srcFile = new File(srcDir, bundleName + ".tar.gz");
    File destDir = this.getStagedBundleDirectory();
    _log.info("deleting " + destDir);
    // cleanup from past run
    try {
        FileUtils.deleteDirectory(destDir);
    } catch (Exception any) {
        _log.info("deleteDir failed with :", any);
    }
    FileUtility fu = new FileUtility();
    _log.info("making directory" + destDir);
    destDir.mkdir();
    _log.info("expanding " + srcFile + " to " + destDir);
    fu.unTargz(srcFile, destDir);
    File oldDir = new File(destDir + File.separator + bundleName);
    File newDir = new File(destDir + File.separator + env);
    _log.info("moving " + oldDir + " to " + newDir);
    FileUtils.moveDirectory(oldDir, newDir);
}
Also used : FileUtility(org.onebusaway.util.FileUtility) BundleFile(org.onebusaway.admin.bundle.model.BundleFile) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with FileUtility

use of org.onebusaway.util.FileUtility in project onebusaway-application-modules by camsys.

the class SyncBundleAction method unzipBundle.

private void unzipBundle(String tmpDir, String bundleFileName) throws IOException {
    byte[] buffer = new byte[1024];
    GZIPInputStream zipIn = new GZIPInputStream(new FileInputStream(tmpDir + File.separator + bundleFileName));
    FileOutputStream out = new FileOutputStream(tmpDir + File.separator + "unzippedBundle");
    int len;
    while ((len = zipIn.read(buffer)) > 0) {
        out.write(buffer, 0, len);
    }
    zipIn.close();
    out.close();
    // Now to untar the unzipped file
    File tarFile = new File(tmpDir + File.separator + "unzippedBundle");
    File untarredFile = new File(tmpDir + File.separator + "untarredBundle");
    // File untarredFile = new File(tmpDir);
    try {
        List<File> fileList = (new FileUtility()).unTar(tarFile, untarredFile);
    } catch (ArchiveException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return;
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) FileOutputStream(java.io.FileOutputStream) FileUtility(org.onebusaway.util.FileUtility) ArchiveException(org.apache.commons.compress.archivers.ArchiveException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 3 with FileUtility

use of org.onebusaway.util.FileUtility in project onebusaway-application-modules by camsys.

the class DirectoryBundleDeployerImpl method setup.

@PostConstruct
public void setup() {
    _fileUtil = new FileUtility();
    _nycFileUtils = new NYCFileUtils();
}
Also used : NYCFileUtils(org.onebusaway.admin.util.NYCFileUtils) FileUtility(org.onebusaway.util.FileUtility) PostConstruct(javax.annotation.PostConstruct)

Example 4 with FileUtility

use of org.onebusaway.util.FileUtility in project onebusaway-application-modules by camsys.

the class BaseModTask method cleanup.

private String cleanup(GtfsBundle gtfsBundle) throws Exception {
    File gtfsFile = gtfsBundle.getPath();
    FileUtility fu = new FileUtility();
    NYCFileUtils fs = new NYCFileUtils();
    _log.info("gtfsBundle.getPath=" + gtfsFile.getPath());
    String oldGtfsName = gtfsFile.getPath().toString();
    // delete the old zip file
    _log.info("deleting " + gtfsFile.getPath());
    gtfsFile.delete();
    // create a new zip file
    String newGtfsName = fs.parseDirectory(oldGtfsName) + File.separator + fs.parseFileNameMinusExtension(oldGtfsName) + "_mod.zip";
    String basePath = fs.parseDirectory(oldGtfsName);
    String includeExpression = ".*\\.txt";
    fu.zip(newGtfsName, basePath, includeExpression);
    int deletedFiles = fu.deleteFilesInFolder(basePath, includeExpression);
    if (deletedFiles < 1) {
        throw new IllegalStateException("Missing expected modded gtfs files in directory " + basePath);
    }
    gtfsBundle.setPath(new File(newGtfsName));
    _log.info("gtfsBundle.getPath(mod)=" + gtfsBundle.getPath() + " with mappings= " + gtfsBundle.getAgencyIdMappings());
    if (getOutputDirectory() != null) {
        File outputDir = new File(getOutputDirectory() + File.separator + getDirectoryHint());
        if (!outputDir.exists() || !outputDir.isDirectory()) {
            outputDir.mkdirs();
        }
        String outputLocation = getOutputDirectory() + File.separator + getDirectoryHint() + File.separator + fs.parseFileName(newGtfsName).replaceAll("_mod", "");
        // copy to outputs for downstream systems
        NYCFileUtils.copyFile(new File(newGtfsName), new File(outputLocation));
    }
    return newGtfsName;
}
Also used : NYCFileUtils(org.onebusaway.admin.util.NYCFileUtils) FileUtility(org.onebusaway.util.FileUtility) File(java.io.File)

Example 5 with FileUtility

use of org.onebusaway.util.FileUtility in project onebusaway-application-modules by camsys.

the class HastusTranslateTask method postPackage.

private String postPackage(String inputDir, String outputDir, String agencyId) throws Exception {
    FileUtility fu = new FileUtility();
    String filename = outputDir + File.separator + agencyId + "_" + "google_transit.zip";
    String includeExpression = ".*\\.txt";
    fu.zip(filename, inputDir, includeExpression);
    return filename;
}
Also used : FileUtility(org.onebusaway.util.FileUtility)

Aggregations

FileUtility (org.onebusaway.util.FileUtility)5 File (java.io.File)3 NYCFileUtils (org.onebusaway.admin.util.NYCFileUtils)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 PostConstruct (javax.annotation.PostConstruct)1 ArchiveException (org.apache.commons.compress.archivers.ArchiveException)1 BundleFile (org.onebusaway.admin.bundle.model.BundleFile)1