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);
}
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;
}
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();
}
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;
}
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;
}
Aggregations