Example usage for java.io File getAbsoluteFile

List of usage examples for java.io File getAbsoluteFile

Introduction

In this page you can find the example usage for java.io File getAbsoluteFile.

Prototype

public File getAbsoluteFile() 

Source Link

Document

Returns the absolute form of this abstract pathname.

Usage

From source file:com.shieldsbetter.sbomg.Cli.java

private static Plan makePlan(CommandLine cmd) throws OperationException {
    Plan result;/*  w  w w . ja va2 s  .  c o  m*/
    String[] args = cmd.getArgs();

    switch (args.length) {
    case 0: {
        File projectFile = new File("sbomg.yaml");
        if (!projectFile.exists()) {
            throw new OperationException("Zero-argument form must be "
                    + "run in a directory with an sbomg.yaml project " + "descriptor file.");
        }
        result = planFromProjectDescriptor(parseProjectDescriptor(projectFile));
        break;
    }
    case 1: {
        File inputFile = new File(args[0]);
        if (inputFile.getName().equals("sbomg.yaml")) {
            result = planFromProjectDescriptor(parseProjectDescriptor(inputFile));
        } else if (inputFile.getName().endsWith((".sbomg"))) {
            inputFile = inputFile.getAbsoluteFile();

            result = singleFilePlan(inputFile, findProjectDescriptor(inputFile));
        } else {
            throw new OperationException(
                    "Input file to one-argument " + "form must indicate an sbomg.yaml project "
                            + "descriptor file or a .sbomg model file rooted "
                            + "in a directory with a project descriptor file.");
        }

        break;
    }
    default: {
        if (args.length > 3) {
            throw new OperationException("Too many arguments.");
        }

        String packageSpec = args[1];
        String outputPathFilename;
        if (args.length == 3) {
            outputPathFilename = args[2];
        } else {
            outputPathFilename = System.getProperty("user.dir");
        }

        result = explicitPlan(new File(args[0]), packageSpec, new File(outputPathFilename));
    }
    }

    return result;
}

From source file:it.polimi.diceH2020.plugin.control.DICEWrap.java

/**
 * Creates JSIM model (.jsimg) from pnml in the given directory  
 * //w ww  .j a va 2 s  . c o  m
 * @throws IOException
 */

public static void genJSIM(int cdid, String alt, String lastTransactionId) throws IOException {
    Configuration conf = Configuration.getCurrent();
    File sparkIdx = new File(Preferences.getSavingDir() + "spark.idx");
    String fileName;

    if (Configuration.getCurrent().getIsPrivate()) {
        fileName = Preferences.getSavingDir() + conf.getID() + "J" + cdid + "inHouse" + alt;
    } else {
        fileName = Preferences.getSavingDir() + conf.getID() + "J" + cdid + alt.replaceAll("-", "");
    }

    try {
        FileWriter fw = new FileWriter(sparkIdx.getAbsoluteFile());
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write(lastTransactionId);
        bw.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    String pnmlPath = Preferences.getSavingDir() + conf.getID() + "J" + cdid + alt.replaceAll("-", "")
            + ".pnml";
    String outputPath = new File(fileName + ".jsimg").getAbsolutePath();
    String indexPath = sparkIdx.getAbsolutePath();

    String command = String.format("java -cp %sbin:%slib/* PNML_Pre_Processor gspn %s %s %s",
            Preferences.getJmTPath(), Preferences.getJmTPath(), pnmlPath, outputPath, indexPath);

    System.out.println("Calling PNML_Pre_Processor");
    System.out.println(command);

    Process proc;

    try {
        proc = Runtime.getRuntime().exec(command);
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }

    try {
        proc.waitFor();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

}

From source file:adams.data.image.ImageMetaDataHelper.java

/**
 * Reads the meta-data from the file (Commons Imaging).
 *
 * @param file   the file to read the meta-data from
 * @return      the meta-data/*from  ww  w. j a  va2  s.c  o  m*/
 * @throws Exception   if failed to read meta-data
 */
public static SpreadSheet commons(File file) throws Exception {
    SpreadSheet sheet;
    Row row;
    org.apache.commons.imaging.common.ImageMetadata meta;
    String[] parts;
    String key;
    String value;
    org.apache.commons.imaging.ImageInfo info;
    String infoStr;
    String[] lines;
    HashSet<String> keys;

    sheet = new DefaultSpreadSheet();

    // header
    row = sheet.getHeaderRow();
    row.addCell("K").setContent("Key");
    row.addCell("V").setContent("Value");

    keys = new HashSet<String>();

    // meta-data
    meta = Imaging.getMetadata(file.getAbsoluteFile());
    if (meta != null) {
        for (Object item : meta.getItems()) {
            key = null;
            value = null;
            if (item instanceof ImageMetadata.Item) {
                key = ((ImageMetadata.Item) item).getKeyword().trim();
                value = ((ImageMetadata.Item) item).getText().trim();
            } else {
                parts = item.toString().split(": ");
                if (parts.length == 2) {
                    key = parts[0].trim();
                    value = parts[1].trim();
                }
            }
            if (key != null) {
                if (!keys.contains(key)) {
                    keys.add(key);
                    row = sheet.addRow();
                    row.addCell("K").setContent(key);
                    row.addCell("V").setContent(fixDateTime(Utils.unquote(value)));
                }
            }
        }
    }

    // image info
    info = Imaging.getImageInfo(file.getAbsoluteFile());
    if (info != null) {
        infoStr = info.toString();
        lines = infoStr.split(System.lineSeparator());
        for (String line : lines) {
            parts = line.split(": ");
            if (parts.length == 2) {
                key = parts[0].trim();
                value = parts[1].trim();
                if (!keys.contains(key)) {
                    row = sheet.addRow();
                    row.addCell("K").setContent(key);
                    row.addCell("V").setContent(Utils.unquote(value));
                    keys.add(key);
                }
            }
        }
    }

    return sheet;
}

From source file:com.ms.commons.test.tool.util.AutoDeleteProjectTaskUtil.java

public static Task wrapAutoDeleteTask(final File project, final Task oldTask) {

    String userDir = System.getProperty("user.dir");

    List<Element> projectElements = ClassPathAccessor.getElementsByXPath(project, "/project");
    if ((projectElements == null) || (projectElements.size() != 1)) {
        System.err.println("File '" + project + "' format error!");
        System.exit(-1);/*from w w  w  .  jav  a  2  s  .com*/
    }
    final String projectId = projectElements.get(0).getAttributeValue("id");
    final String projectExtends = projectElements.get(0).getAttributeValue("extends");

    System.out.println("Project id:" + projectId);
    System.out.println("Project extends:" + projectExtends);

    final File baseProject = new File(userDir + File.separator + projectExtends);
    if (!baseProject.exists()) {
        System.err.println("Base file '" + baseProject + "' not found!");
        System.exit(-1);
    }

    List<Element> findProjectIdElements = ClassPathAccessor.getElementsByXPath(baseProject,
            "/project/projects/project[@id='" + projectId + "']");

    if ((findProjectIdElements != null) && (findProjectIdElements.size() > 0)) {
        System.out.println("Find project id in base project file.");
        return new Task() {

            @SuppressWarnings("unchecked")
            public void finish() {
                boolean hasError = false;
                File backUpFile = new File(baseProject.getAbsoluteFile() + ".backup");
                try {
                    FileUtils.copyFile(baseProject, backUpFile);

                    // XMLAPI
                    List<String> outLines = new ArrayList<String>();
                    List<String> lines = FileUtils.readLines(baseProject);
                    for (String line : lines) {
                        if (!(line.contains("\"" + projectId + "\""))) {
                            outLines.add(line);
                        }
                    }
                    FileUtils.writeLines(baseProject, outLines);

                    oldTask.finish();
                } catch (Exception e) {
                    hasError = true;
                    e.printStackTrace();
                } finally {
                    baseProject.delete();
                    try {
                        FileUtils.copyFile(backUpFile, baseProject);
                    } catch (IOException e) {
                        hasError = true;
                        e.printStackTrace();
                    }
                    backUpFile.delete();
                }
                if (hasError) {
                    System.exit(-1);
                }
            }
        };
    } else {
        System.out.println("Not find project id in base project file.");
    }

    return oldTask;
}

From source file:caesar.feng.framework.utils.ACache.java

public static ACache get(File cacheDir, long max_zise, int max_count) {
    ACache manager = mInstanceMap.get(cacheDir.getAbsoluteFile() + myPid());
    if (manager == null) {
        manager = new ACache(cacheDir, max_zise, max_count);
        mInstanceMap.put(cacheDir.getAbsolutePath() + myPid(), manager);
    }//from  w  w w .j  av  a  2  s. com
    return manager;
}

From source file:com.hp.test.framework.Utlis.java

public static void getpaths(String path) {
    // log.info("started getting all the documents paths :::" + path);
    File root = new File(path);
    File[] list = root.listFiles();
    if (list == null) {
        return;/*from  w  ww  .  j av  a 2  s . c  om*/
    }
    for (File f : list) {
        if (f.isDirectory()) {
            getpaths(f.getAbsolutePath());

        } else {

            String filename = f.getName();
            String Abpath = f.getAbsolutePath();
            String extension = "";
            int i = filename.lastIndexOf('.');
            if (i >= 0) {
                extension = filename.substring(i + 1);
                if (extension.contentEquals("html")) {
                    System.out.println("File:" + f.getAbsoluteFile());
                    fileList.add(new File(f.getAbsolutePath()));
                }
            }

        }
    }
}

From source file:com.geekworld.cheava.yummy.utils.ACache.java

public static ACache get(File cacheDir, long max_zise, int max_count) {
    ACache manager = mInstanceMap.get(cacheDir.getAbsoluteFile() + myPid());
    if (manager == null) {
        manager = new ACache(cacheDir, max_zise, max_count);
        Log.i("Acache", myPid());
        mInstanceMap.put(cacheDir.getAbsolutePath() + myPid(), manager);
    }//from ww  w .  ja  va2  s  .  com
    return manager;
}

From source file:se.bitcraze.crazyflielib.bootloader.Bootloader.java

public static byte[] readFile(File file) throws IOException {
    byte[] fileData = new byte[(int) file.length()];
    Logger logger = LoggerFactory.getLogger("Bootloader");
    logger.debug("readFile: " + file.getName() + ", size: " + file.length());
    RandomAccessFile raf = null;/*from   w w  w.j a v  a  2  s . c  o m*/
    try {
        raf = new RandomAccessFile(file.getAbsoluteFile(), "r");
        raf.readFully(fileData);
    } finally {
        if (raf != null) {
            try {
                raf.close();
            } catch (IOException ioe) {
                logger.error(ioe.getMessage());
            }
        }
    }
    return fileData;
}

From source file:cn.scau.scautreasure.util.CacheUtil.java

public static CacheUtil get(File cacheDir, long max_zise, int max_count) {
    CacheUtil manager = mInstanceMap.get(cacheDir.getAbsoluteFile() + myPid());
    if (manager == null) {
        manager = new CacheUtil(cacheDir, max_zise, max_count);
        mInstanceMap.put(cacheDir.getAbsolutePath() + myPid(), manager);
    }/*from  w  ww.j a  v a  2  s.co  m*/
    return manager;
}

From source file:com.soubw.cache.ACache.java

public static ACache get(File cacheDir, long max_size, int max_count) {
    ACache manager = mInstanceMap.get(cacheDir.getAbsoluteFile() + myPid());
    if (manager == null) {
        manager = new ACache(cacheDir, max_size, max_count);
        mInstanceMap.put(cacheDir.getAbsolutePath() + myPid(), manager);
    }//from w  ww. jav  a  2 s  .  c  om
    return manager;
}