Java Code Examples for java.io.File#getParent()

The following examples show how to use java.io.File#getParent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SunFontManager.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private PhysicalFont findOtherDeferredFont(String name, int style) {
    for (String fileName : deferredFontFiles.keySet()) {
        File file = new File(fileName);
        String dir = file.getParent();
        String fname = file.getName();
        if (dir != null &&
            dir.equals(jreFontDirName) &&
            jreLucidaFontFiles.contains(fname)) {
            continue;
        }
        PhysicalFont physicalFont = initialiseDeferredFont(fileName);
        if (physicalFont != null &&
            (physicalFont.getFontName(null).equalsIgnoreCase(name) ||
            physicalFont.getFamilyName(null).equalsIgnoreCase(name)) &&
            physicalFont.style == style) {
            return physicalFont;
        }
    }
    return null;
}
 
Example 2
Source File: PathResolverTest.java    From sonar-ruby-plugin with MIT License 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    URL filePath = PathResolverTest.class.getClassLoader().getResource("./test_controller.rb");
    existingFile = new File(filePath.toURI());
    String parentPath = existingFile.getParent();

    this.sensorContext = SensorContextTester.create(new File(parentPath));
    this.sensorContext.settings().setProperty("path key", "test_controller.rb");

    DefaultInputFile file =
        new DefaultInputFile("", "test_controller.rb")
            .setLanguage(Ruby.LANGUAGE_KEY);

    this.sensorContext.fileSystem().add(file);

    this.resolver = new PathResolver();
}
 
Example 3
Source File: ShellCommandsDUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public void testHistoryWithFileName() {
  Gfsh gfshInstance = Gfsh.getCurrentInstance();

  if (gfshInstance == null) {
    fail("In testHistory command gfshInstance is null");
  }

  String historyFileName = gfshInstance.getGfshConfig().getHistoryFileName();
  File historyFile = new File(historyFileName);
  String fileName = historyFile.getParent();
  fileName = fileName + File.separator + getClass().getSimpleName() + "_" + getName() + "-exported.history";
  
  String command = "history --file="+fileName;
  CommandResult cmdResult = executeCommand(command);

  if (cmdResult != null) {
    assertEquals(Result.Status.OK, cmdResult.getStatus());
  } else {
    fail("testHistory failed");
  }    
}
 
Example 4
Source File: HttpDFileInfoTask.java    From Aria with Apache License 2.0 6 votes vote down vote up
/**
 * 重命名文件
 */
private void renameFile(String newName) {
  if (TextUtils.isEmpty(newName)) {
    ALog.w(TAG, "重命名失败【服务器返回的文件名为空】");
    return;
  }
  ALog.d(TAG, String.format("文件重命名为:%s", newName));
  File oldFile = new File(mEntity.getFilePath());
  String newPath = oldFile.getParent() + "/" + newName;
  if (!CheckUtil.checkDPathConflicts(false, newPath, mTaskWrapper.getRequestType())) {
    ALog.e(TAG, "文件重命名失败");
    return;
  }
  if (oldFile.exists()) {
    boolean b = oldFile.renameTo(new File(newPath));
    ALog.d(TAG, String.format("文件重命名%s", b ? "成功" : "失败"));
  }
  mEntity.setFileName(newName);
  mEntity.setFilePath(newPath);
  RecordUtil.modifyTaskRecord(oldFile.getPath(), newPath, mEntity.getTaskType());
}
 
Example 5
Source File: GtkFileDialogPeer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private void showNativeDialog() {
    String dirname = fd.getDirectory();
    // File path has a priority against directory path.
    String filename = fd.getFile();
    if (filename != null) {
        final File file = new File(filename);
        if (fd.getMode() == FileDialog.LOAD
            && dirname != null
            && file.getParent() == null) {
            // File path for gtk_file_chooser_set_filename.
            filename = dirname + (dirname.endsWith(File.separator) ? "" :
                                          File.separator) + filename;
        }
        if (fd.getMode() == FileDialog.SAVE && file.getParent() != null) {
            // Filename for gtk_file_chooser_set_current_name.
            filename = file.getName();
            // Directory path for gtk_file_chooser_set_current_folder.
            dirname = file.getParent();
        }
    }
    run(fd.getTitle(), fd.getMode(), dirname, filename,
        fd.getFilenameFilter(), fd.isMultipleMode(), fd.getX(), fd.getY());
}
 
Example 6
Source File: AquaFileChooserUI.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds the directory to the model and sets it to be selected,
 * additionally clears out the previous selected directory and
 * the paths leading up to it, if any.
 */
void addItem(final File directory) {
    if (directory == null) { return; }
    if (fSelectedDirectory != null) {
        removeSelectedDirectory();
    }

    // create File instances of each directory leading up to the top
    File f = directory.getAbsoluteFile();
    final Vector<File> path = new Vector<File>(10);
    while (f.getParent() != null) {
        path.addElement(f);
        f = getFileChooser().getFileSystemView().createFileObject(f.getParent());
    };

    // Add root file (the desktop) to the model
    final File[] roots = getFileChooser().getFileSystemView().getRoots();
    for (final File element : roots) {
        path.addElement(element);
    }
    fPathCount = path.size();

    // insert all the path fDirectories leading up to the
    // selected directory in reverse order (current directory at top)
    for (int i = 0; i < path.size(); i++) {
        fDirectories.addElement(path.elementAt(i));
    }

    setSelectedItem(fDirectories.elementAt(0));

    // dump();
}
 
Example 7
Source File: Activator.java    From erflute with Apache License 2.0 5 votes vote down vote up
public static String showSaveDialog(String filePath, String[] filterExtensions) {
    String dir = null;
    String fileName = null;
    if (filePath != null && !"".equals(filePath.trim())) {
        final File file = new File(filePath.trim());
        dir = file.getParent();
        fileName = file.getName();
    }
    final FileDialog fileDialog = new FileDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.SAVE);
    fileDialog.setFilterPath(dir);
    fileDialog.setFileName(fileName);
    fileDialog.setFilterExtensions(filterExtensions);
    return fileDialog.open();
}
 
Example 8
Source File: Driver.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
protected File compileTestFile(File f, String testClass) {
    int rc = com.sun.tools.javac.Main.compile(new String[] { "-source", "1.8", "-g", f.getPath() });
    if (rc != 0)
        throw new Error("compilation failed. rc=" + rc);
    String path;
    if (f.getParent() != null) {
        path = f.getParent();
    } else {
        path = "";
    }

    return new File(path + testClass + ".class");
}
 
Example 9
Source File: TilesetConverter.java    From stendhal with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Load tile mapping information from the standard input.
 *
 * @param path The path of the <b>map</b>. Needed for proper
 * conversion of the tileset paths.
 * @throws IOException
 */
private void loadMapping(String path) throws IOException {
	BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

	// needed for constructing the full path of the tilesets
	File f = new File(path);
	String dir = f.getParent();

	String line;
	while ((line = input.readLine()) != null) {
		String[] elements = line.split(":", -1);
		if (elements.length != 4) {
			System.err.println("Invalid line: '" + line + "'");
		} else {
			int newIndex = 0;
			if (!"".equals(elements[3])) {
				newIndex = Integer.parseInt(elements[3]);
			}

			/*
			 * Oh, yay. Tiled likes to translate the filenames internally
			 * to full paths.
			 * Great fun with java to compare the paths when the system
			 * allows no playing with directories whatsoever. We can't rely
			 * on the current directory being the same as that of the map.
			 * Building the full path from scratch, and hope for the best.
			 */
			String path1 = (new File(dir + File.separator + elements[0])).getCanonicalPath();
			String path2 = (new File(dir + File.separator + elements[2])).getCanonicalPath();

			mapping.addMapping(path1, Integer.parseInt(elements[1]), path2, newIndex);
		}
	}
}
 
Example 10
Source File: FileUtils.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
public static boolean uncompress(File zipFile) {
    boolean success = false;
    try {
        FileInputStream fis = new FileInputStream(zipFile);
        ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
        ZipEntry entry;
        File destFolder = new File(zipFile.getParent(), FileUtils.getNameFromFilename(zipFile.getName()));
        destFolder.mkdirs();
        while ((entry = zis.getNextEntry()) != null) {
            File dest = new File(destFolder, entry.getName());
            dest.getParentFile().mkdirs();

            if(entry.isDirectory()) {
                if (!dest.exists()) {
                    dest.mkdirs();
                }
            } else {
                int size;
                byte[] buffer = new byte[2048];
                FileOutputStream fos = new FileOutputStream(dest);
                BufferedOutputStream bos = new BufferedOutputStream(fos, buffer.length);
                while ((size = zis.read(buffer, 0, buffer.length)) != -1) {
                    bos.write(buffer, 0, size);
                }
                bos.flush();
                bos.close();
                IoUtils.flushQuietly(bos);
                IoUtils.closeQuietly(bos);
            }
            zis.closeEntry();
        }
        IoUtils.closeQuietly(zis);
        IoUtils.closeQuietly(fis);
        success = true;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return success;
}
 
Example 11
Source File: TestUtils.java    From wisp with Apache License 2.0 5 votes vote down vote up
private static List<Class> getClassList(String pack) {
    List<Class> classList = null;
    String packagePath = pack.replace(".", "/");
    if (CLASS_PATH != null) {
        String type = CLASS_PATH.getProtocol();
        if (type.equals("file")) {
            File file = new File(CLASS_PATH.getPath());
            String path = file.getParent() + CLASSES + packagePath;
            classList = getClassListByFilter(new File(path), pack);
        }
    }
    return classList;
}
 
Example 12
Source File: AbstractCleanUpPolicyTest.java    From kafka-connect-spooldir with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void before() throws IOException {
  this.errorPath = Files.createTempDir();
  this.finishedPath = Files.createTempDir();
  File inputFile = File.createTempFile("input", "file");
  File processingFlag = new File(inputFile.getParent(), inputFile.getName() + ".PROCESSING");
  this.inputFile = new InputFile(inputFile, processingFlag, 0);
  this.cleanupPolicy = create(this.inputFile, this.errorPath, this.finishedPath);
}
 
Example 13
Source File: SunSDK.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the home directory of a Java 2 SDK if the current
 * JRE is embedded in one.
 */
static String home() {
    File jreHome = new File(System.getProperty("java.home"));
    File jreParent = new File(jreHome.getParent());

    String jdwpLibName = "bin" + File.separator +
                         System.mapLibraryName("jdwp");
    File jdwpLib = new File(jreParent, jdwpLibName);
    return jdwpLib.exists() ? jreParent.getAbsolutePath() : null;
}
 
Example 14
Source File: ProjectUtils.java    From developer-studio with Apache License 2.0 5 votes vote down vote up
public static String fileNameWithExtension(String fileName){
    File file = new File(fileName);
    if (file.isDirectory()) return fileName;
    String name = file.getName();
    final int lastPeriodPos = name.lastIndexOf('.', name.length() - 1);
    if (lastPeriodPos == -1){
        return fileName;
    }
    else {
        File nameWithoutExt = new File(file.getParent(), name.substring(0, lastPeriodPos)+"_"+name.substring(lastPeriodPos+1).toLowerCase());
        return nameWithoutExt.getPath();
    }

}
 
Example 15
Source File: FileUtilsJ.java    From Tok-Android with GNU General Public License v3.0 5 votes vote down vote up
public static String rename(String filePath, String newName) {
    if (StringUtils.isEmpty(filePath) || StringUtils.isEmpty(newName)) {
        return null;
    }
    File file = new File(filePath);
    String parent = file.getParent();
    File newFile = new File(parent, newName);
    if (newFile.exists()) {
        return null;
    }
    return file.renameTo(newFile) ? newFile.getAbsolutePath() : null;
}
 
Example 16
Source File: JavaToWSDLProcessor.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected File getOutputDir(File wsdlLocation) {
    String dir = (String)context.get(ToolConstants.CFG_OUTPUTDIR);
    if (dir == null) {
        if (wsdlLocation == null
            || wsdlLocation.getParentFile() == null
            || !wsdlLocation.getParentFile().exists()) {
            dir = "./";
        } else {
            dir = wsdlLocation.getParent();
        }
    }
    return new File(dir);
}
 
Example 17
Source File: ChartThemesApp.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 *
 */
public void pptx() throws JRException
{
	long start = System.currentTimeMillis();
	File sourceFile = new File("build/reports/AllChartsReport.jrprint");

	JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile);

	File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".pptx");
	
	JRPptxExporter exporter = new JRPptxExporter();
	
	exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
	exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile));

	exporter.exportReport();

	System.err.println("PPTX creation time : " + (System.currentTimeMillis() - start));
}
 
Example 18
Source File: XlsxDataSourceApp.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 *
 */
public void odt() throws JRException
{
	long start = System.currentTimeMillis();
	File sourceFile = new File("build/reports/XlsxDataSourceReport.jrprint");

	JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile);

	File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".odt");
	
	JROdtExporter exporter = new JROdtExporter();
	
	exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
	exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile));
	
	exporter.exportReport();

	System.err.println("ODT creation time : " + (System.currentTimeMillis() - start));
}
 
Example 19
Source File: SunFontManager.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public
/*private*/ PhysicalFont findJREDeferredFont(String name, int style) {

    PhysicalFont physicalFont;
    String nameAndStyle = name.toLowerCase(Locale.ENGLISH) + style;
    String fileName = jreFontMap.get(nameAndStyle);
    if (fileName != null) {
        fileName = jreFontDirName + File.separator + fileName;
        if (deferredFontFiles.get(fileName) != null) {
            physicalFont = initialiseDeferredFont(fileName);
            if (physicalFont != null &&
                (physicalFont.getFontName(null).equalsIgnoreCase(name) ||
                 physicalFont.getFamilyName(null).equalsIgnoreCase(name))
                && physicalFont.style == style) {
                return physicalFont;
            }
        }
    }

    /* Iterate over the deferred font files looking for any in the
     * jre directory that we didn't recognise, open each of these.
     * In almost all installations this will quickly fall through
     * because only the Lucidas will be present and jreOtherFontFiles
     * will be empty.
     * noOtherJREFontFiles is used so we can skip this block as soon
     * as its determined that its not needed - almost always after the
     * very first time through.
     */
    if (noOtherJREFontFiles) {
        return null;
    }
    synchronized (jreLucidaFontFiles) {
        if (jreOtherFontFiles == null) {
            HashSet<String> otherFontFiles = new HashSet<String>();
            for (String deferredFile : deferredFontFiles.keySet()) {
                File file = new File(deferredFile);
                String dir = file.getParent();
                String fname = file.getName();
                /* skip names which aren't absolute, aren't in the JRE
                 * directory, or are known Lucida fonts.
                 */
                if (dir == null ||
                    !dir.equals(jreFontDirName) ||
                    jreLucidaFontFiles.contains(fname)) {
                    continue;
                }
                otherFontFiles.add(deferredFile);
            }
            jreOtherFontFiles = otherFontFiles.toArray(STR_ARRAY);
            if (jreOtherFontFiles.length == 0) {
                noOtherJREFontFiles = true;
            }
        }

        for (int i=0; i<jreOtherFontFiles.length;i++) {
            fileName = jreOtherFontFiles[i];
            if (fileName == null) {
                continue;
            }
            jreOtherFontFiles[i] = null;
            physicalFont = initialiseDeferredFont(fileName);
            if (physicalFont != null &&
                (physicalFont.getFontName(null).equalsIgnoreCase(name) ||
                 physicalFont.getFamilyName(null).equalsIgnoreCase(name))
                && physicalFont.style == style) {
                return physicalFont;
            }
        }
    }

    return null;
}
 
Example 20
Source File: GradleWrapperMain.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private static File wrapperProperties(File wrapperJar) {
    return new File(wrapperJar.getParent(), wrapperJar.getName().replaceFirst("\\.jar$", ".properties"));
}