Java Code Examples for org.apache.commons.io.FilenameUtils.removeExtension()

The following are Jave code examples for showing how to use removeExtension() of the org.apache.commons.io.FilenameUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: DIA-Umpire-Maven   File: mzXMLParser.java   View Source Code Vote up 6 votes
private boolean FSScanPosRead() {
    if (!new File(FilenameUtils.removeExtension(filename) + ".ScanPosFS").exists()) {
        return false;
    }
    try {
        Logger.getRootLogger().debug("Reading ScanPos:" + FilenameUtils.removeExtension(filename) + ".ScanPosFS...");
        FileInputStream fileIn = new FileInputStream(FilenameUtils.removeExtension(filename) + ".ScanPosFS");
        FSTObjectInput in = new FSTObjectInput(fileIn);
        ScanIndex = (TreeMap<Integer, Long>) in.readObject();
        TotalScan = ScanIndex.size();
        in.close();
        fileIn.close();

    } catch (Exception ex) {
        Logger.getRootLogger().debug("ScanIndex serialization file failed");
        //Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
        return false;
    }
    return true;
}
 
Example 2
Project: pdi-git-plugin   File: UIGit.java   View Source Code Vote up 6 votes
@Override
public void add( String filepattern ) {
  try {
    if ( filepattern.endsWith( ".ours" ) || filepattern.endsWith( ".theirs" ) ) {
      FileUtils.rename( new File( directory, filepattern ),
          new File( directory, FilenameUtils.removeExtension( filepattern ) ),
          StandardCopyOption.REPLACE_EXISTING );
      filepattern = FilenameUtils.removeExtension( filepattern );
      org.apache.commons.io.FileUtils.deleteQuietly( new File( directory, filepattern + ".ours" ) );
      org.apache.commons.io.FileUtils.deleteQuietly( new File( directory, filepattern + ".theirs" ) );
    }
    git.add().addFilepattern( filepattern ).call();
  } catch ( Exception e ) {
    showMessageBox( BaseMessages.getString( PKG, "Dialog.Error" ), e.getMessage() );
  }
}
 
Example 3
Project: otter-G   File: ArchiveBeanIntegration.java   View Source Code Vote up 6 votes
@Test
public void test_unpack() {
    ArchiveBean archiveBean = new ArchiveBean();
    try {
        archiveBean.afterPropertiesSet();
        archiveBean.setUseLocalFileMutliThread(false);
    } catch (Exception e1) {
        want.fail();
    }

    File archiveFile = new File("/tmp/otter/test.gzip");
    // for (File archiveFile : archiveFiles.listFiles()) {
    // if (archiveFile.isDirectory()) {
    // continue;
    // }
    //
    // if (!"FileBatch-2013-03-07-16-27-05-245-369-3209577.gzip".equals(archiveFile.getName())) {
    // continue;
    // }

    System.out.println("start unpack : " + archiveFile.getName());
    File targetFile = new File("/tmp/otter", FilenameUtils.removeExtension(archiveFile.getName()));
    archiveBean.unpack(archiveFile, targetFile);
    // }
}
 
Example 4
Project: hygene   File: Snapshot.java   View Source Code Vote up 5 votes
/**
 * Uses a GFA file to determine the destination and constructs a new {@link Snapshot}.
 *
 * @param gfaFile a {@link GfaFile} instance
 * @return a new {@link Snapshot}
 */
public static Snapshot forGfaFile(final GfaFile gfaFile) {
    final File file = new File(gfaFile.getFileName());
    final String gfaFileNameWithoutExtension = FilenameUtils.removeExtension(file.getName());

    final String fileName = gfaFileNameWithoutExtension + "_snapshot_" + new Date().getTime() + "." + FILE_FORMAT;
    final File destination = new File(file.getParent(), fileName);

    return new Snapshot(destination);
}
 
Example 5
Project: onprom   File: OnpromToolkit.java   View Source Code Vote up 5 votes
private Void saveAll() {
  File selectedFile = IOUtility.selectFileToSave(FileType.ONTOLOGY);
  if (selectedFile != null) {
    String fileName = FilenameUtils.removeExtension(selectedFile.getAbsolutePath());
    for (int i = 0; i < objects.getCount(); i++) {
      TreeNode node = objects.getNode(i);
      saveObject(fileName, node.getType(), node.getUserObject());
    }
  }
  return null;
}
 
Example 6
Project: hdr-histogram-plotter   File: HdrLogProcessorWrapper.java   View Source Code Vote up 5 votes
public String convertLog(String path) throws IOException {
    String args[] = {
            "-i", path,
            "-outputValueUnitRatio", unitRatio,
            "-csv"
    };

    String csvFile = FilenameUtils.removeExtension(path) + ".csv";
    PrintStream oldOut = System.out;

    try (FileOutputStream fileStream = new FileOutputStream(csvFile)) {
        PrintStream newOutStream = new PrintStream(fileStream);

        /*
         * By default it prints on stdout. Since it does not seem to provide an easy
         * way to save to a file via API, then just replace the stdout for saving the
         * CSV data.
         */

        System.setOut(newOutStream);

        HistogramLogProcessor processor = new HistogramLogProcessor(args);
        processor.run();

        /*
         * Restore it after use
         */

    } finally {
        System.setOut(oldOut);
    }


    return csvFile;
}
 
Example 7
Project: buenojo   File: PhotoLocationLoader.java   View Source Code Vote up 5 votes
private void loadSatelliteImages(PhotoLocationExercise exercise, Path exercisePath, Boolean dryRun) throws IOException, BuenOjoCSVParserException, InvalidSatelliteImageType, BuenOjoFileException, BuenOjoInconsistencyException, BuenOjoDataSetException{
	List<Path> satelliteImagePaths = Files.walk(exercisePath, 1, FileVisitOption.FOLLOW_LINKS).filter(p -> {
		Optional<String> type = BuenOjoFileUtils.contentType(p);
		return type.isPresent() && type.get() != "text/csv";
	}).collect(Collectors.toList());
	
	List<SatelliteImage> satelliteImages = new ArrayList<>();
	for (Path path : satelliteImagePaths) {
		String filename = FilenameUtils.removeExtension(path.getFileName().toString());
		Path csv = path.resolveSibling(filename+".csv");
		SatelliteImage s = satelliteImageFactory.imageFromFile(BuenOjoFileUtils.multipartFile(path), BuenOjoFileUtils.multipartFile(csv), dryRun);
		satelliteImages.add(s);
	}
	satelliteImageRepository.save(satelliteImages);
	
	List<PhotoLocationSatelliteImage> pImages = new ArrayList<>();
	
	for (SatelliteImage satelliteImage : satelliteImages) {
		PhotoLocationSatelliteImage pImg = PhotoLocationSatelliteImage.fromSatelliteImage(satelliteImage);
		pImg.setKeywords(exercise.getLandscapeKeywords());
		pImages.add(pImg);
		
	}
	
	photoLocationSatelliteImageRepository.save(pImages);
	
	exercise.setSatelliteImages(new HashSet<>(pImages));
}
 
Example 8
Project: visitormanagement   File: Util.java   View Source Code Vote up 5 votes
/**
 * This method will return default image when visitor image in not available.
 * 
 * @throws IOException 
 * @return file
 */
public static File createDefaultImageFile(Resource resource, String path) throws IOException {
	String fileNameWithOutExt = FilenameUtils.removeExtension(path);
	InputStream inputStream = resource.getInputStream();
	File tempFile = File.createTempFile(fileNameWithOutExt, "."+FilenameUtils.getExtension(path));
	FileUtils.copyInputStreamToFile(inputStream, tempFile);
	return tempFile;
}
 
Example 9
Project: jwala   File: ResourceServiceImpl.java   View Source Code Vote up 5 votes
private void doUnpack(final String hostName, final String destPath) {
    try {
        binaryDistributionService.distributeUnzip(hostName);
        final String zipDestinationOption = FilenameUtils.removeExtension(destPath);
        LOGGER.debug("checking if unpacked destination exists: {}", zipDestinationOption);
        binaryDistributionService.remoteFileCheck(hostName, zipDestinationOption);
        binaryDistributionService.backupFile(hostName, zipDestinationOption);
        binaryDistributionService.remoteUnzipBinary(hostName, destPath, zipDestinationOption, "");
    } catch (CommandFailureException e) {
        LOGGER.error("Failed to execute remote command when unpack to {} ", destPath, e);
        throw new ApplicationException("Failed to execute remote command when unpack to  " + destPath, e);
    }
}
 
Example 10
Project: DIA-Umpire-Maven   File: mzXMLParser.java   View Source Code Vote up 5 votes
private void FSScanPosWrite() {
    try {
        Logger.getRootLogger().debug("Writing ScanPos to file:" + FilenameUtils.removeExtension(filename) + ".ScanPosFS..");
        FileOutputStream fout = new FileOutputStream(FilenameUtils.removeExtension(filename) + ".ScanPosFS", false);
        FSTObjectOutput oos = new FSTObjectOutput(fout);
        oos.writeObject(ScanIndex);
        oos.close();
        fout.close();
    } catch (Exception ex) {
        Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
    }
}
 
Example 11
Project: osc-core   File: BackupData.java   View Source Code Vote up 5 votes
public File writeBackupZipFile(String filePath) throws IOException {
    File backupZipFile = new File(FilenameUtils.removeExtension(filePath) + BackupFileService.EXT_ZIP_BACKUP);
    FileUtils.writeByteArrayToFile(backupZipFile, dbData);
    return backupZipFile;
}
 
Example 12
Project: hdr-histogram-plotter   File: Main.java   View Source Code Vote up 5 votes
public static void main(String[] args) {
    processCommand(args);

    try {
        // HDR Converter
        HdrLogProcessorWrapper processorWrapper;

        processorWrapper = new HdrLogProcessorWrapper(unitRate);

        String csvFile = processorWrapper.convertLog(fileName);

        // CSV Reader
        HdrReader reader = new HdrReader();

        HdrData hdrData = reader.read(csvFile);

        // HdrPlotter
        HdrPlotter plotter = new HdrPlotter(FilenameUtils.removeExtension(fileName), timeUnit);
        plotter.plot(hdrData.getPercentile(), hdrData.getValue());

        HdrPropertyWriter.writeFrom(fileName);

        System.exit(0);
    } catch (Exception e) {
        e.printStackTrace();
        System.err.println(e.getMessage());
    }

    System.exit(1);
}
 
Example 13
Project: Reer   File: CompilerOutputFileNamingScheme.java   View Source Code Vote up 4 votes
public File map(File sourceFile) {
    final String baseName = FilenameUtils.removeExtension(sourceFile.getName());
    String compactMD5 = HashUtil.createCompactMD5(sourceFile.getAbsolutePath());
    File hashDirectory = new File(outputBaseFolder, compactMD5);
    return new File(hashDirectory, baseName + objectFileNameSuffix);
}
 
Example 14
Project: buenojo   File: ImageResourceService.java   View Source Code Vote up 4 votes
private String hiResFilenameForImageResource(ImageResource imageResource){
	String fileExtension = BuenOjoFileUtils.extensionFromContentType(imageResource.getHiResImageContentType());
	String fileName = FilenameUtils.removeExtension(imageResource.getName()) + BuenOjoFileUtils.HI_RES_SUFFIX +FilenameUtils.EXTENSION_SEPARATOR_STR +fileExtension;
	return fileName;
}
 
Example 15
Project: buenojo   File: ImageResourceService.java   View Source Code Vote up 4 votes
private String loResFilenameForImageResource(ImageResource imageResource){
	String fileExtension = BuenOjoFileUtils.extensionFromContentType(imageResource.getLoResImageContentType());
	String fileName = FilenameUtils.removeExtension(imageResource.getName()) +FilenameUtils.EXTENSION_SEPARATOR_STR +fileExtension;
	return fileName;
}
 
Example 16
Project: coffee-gb   File: Cartridge.java   View Source Code Vote up 4 votes
public Cartridge(GameboyOptions options) throws IOException {
    File file = options.getRomFile();
    int[] rom = loadFile(file);
    CartridgeType type = CartridgeType.getById(rom[0x0147]);
    title = getTitle(rom);
    LOG.debug("Cartridge {}, type: {}", title, type);
    gameboyType = GameboyTypeFlag.getFlag(rom[0x0143]);
    int romBanks = getRomBanks(rom[0x0148]);
    int ramBanks = getRamBanks(rom[0x0149]);
    if (ramBanks == 0 && type.isRam()) {
        LOG.warn("RAM bank is defined to 0. Overriding to 1.");
        ramBanks = 1;
    }
    LOG.debug("ROM banks: {}, RAM banks: {}", romBanks, ramBanks);

    Battery battery = Battery.NULL_BATTERY;
    if (type.isBattery() && options.isSupportBatterySaves()) {
        battery = new FileBattery(file.getParentFile(), FilenameUtils.removeExtension(file.getName()));
    }

    if (type.isMbc1()) {
        addressSpace = new Mbc1(rom, type, battery, romBanks, ramBanks);
    } else if (type.isMbc2()) {
        addressSpace = new Mbc2(rom, type, battery, romBanks);
    } else if (type.isMbc3()) {
        addressSpace = new Mbc3(rom, type, battery, romBanks, ramBanks);
    } else if (type.isMbc5()) {
        addressSpace = new Mbc5(rom, type, battery, romBanks, ramBanks);
    } else {
        addressSpace = new Rom(rom, type, romBanks, ramBanks);
    }

    dmgBoostrap = options.isUsingBootstrap() ? 0 : 1;
    if (options.isForceCgb()) {
        gbc = true;
    } else if (gameboyType == Cartridge.GameboyTypeFlag.NON_CGB) {
        gbc = false;
    } else if (gameboyType == Cartridge.GameboyTypeFlag.CGB) {
        gbc = true;
    } else { // UNIVERSAL
        gbc = !options.isForceDmg();
    }
}
 
Example 17
Project: OneClient   File: CurseFullProject.java   View Source Code Vote up 4 votes
public String getFileName() {
	return FilenameUtils.removeExtension(FileName);
}
 
Example 18
Project: oxygen-dita-translation-package-builder   File: ProjectConstants.java   View Source Code Vote up 4 votes
/**
 * @return The name of the HTML report of files contained in the ZIP.
 */
public static String getHTMLReportFile(File ditaRootMap) {
  return FilenameUtils.removeExtension(ditaRootMap.getName()) + REPORT_FILE_SUFFIX;
}
 
Example 19
Project: hdr-histogram-plotter   File: SimpleTest.java   View Source Code Vote up 4 votes
private void plot(String fileName) throws Exception {
    // HDR Converter
    HdrLogProcessorWrapper processorWrapper = new HdrLogProcessorWrapper(HdrLogProcessorWrapper.DEFAULT_UNIT_RATE);


    String csvFile = processorWrapper.convertLog(fileName);

    // CSV Reader
    HdrReader reader = new HdrReader();

    HdrData hdrData = reader.read(csvFile);

    // HdrPlotter
    HdrPlotter plotter = new HdrPlotter(FilenameUtils.removeExtension(fileName));
    plotter.plot(hdrData.getPercentile(), hdrData.getValue());

    HdrPropertyWriter.writeFrom(fileName);
}
 
Example 20
Project: WebPLP   File: PLPProject.java   View Source Code Vote up 4 votes
/**
 * Loads a PLP6 project. The given file must be a directory, and have a structure as
 * specified by {@link #save()}
 * 
 * @param projectDirectory
 *            The directory of the project to load. This file must be a DIRECTORY, and
 *            have a structure as specified by {@link #save()}
 * @return A {@link PLPProject} representative of the information stored in the given
 *         directory.
 * @throws IOException
 */
private static PLPProject loadCurrent(File projectDirectory) throws IOException
{
	validateProjectDirectory(projectDirectory);
	File projectFile = validateAndFilizeProjectFile(projectDirectory);
	
	if (!projectFile.exists())
		throw new IllegalArgumentException("Project file not found.");
		
	String fileString = FileUtils.readFileToString(projectFile);
	JSONObject projectDetails = new JSONObject(fileString);
	String name = projectDetails.optString(NAME_KEY);
	//String type = projectDetails.optString(NAME_KEY);
	String type = projectDetails.optString(TYPE_KEY);
	String sourceDirectoryName = projectDetails.optString(SOURCE_NAME_KEY, "src");
	String lstAsmFiles = projectDetails.optString(SOURCE_FILES);
	String[] listFiles = lstAsmFiles.split(",");
	
	Path projectPath = projectDirectory.toPath();
	Path sourcePath = projectPath.resolve(sourceDirectoryName);
	File sourceDirectory = sourcePath.toFile();
	
	//PLPProject project = new PLPProject(name, type);
	PLPProject project = new PLPProject(name, type, projectPath.toString());
	
	for (String fileName : listFiles)
	{
		String fullPath = FilenameUtils.concat(sourceDirectory.getAbsolutePath(), fileName);
		String sourceName = FilenameUtils.removeExtension(fileName);
		
		SimpleASMFile sourceFile = new SimpleASMFile(project, fileName, AsmFileContent(fullPath));
		project.add(sourceFile);
	}
	
	/*for (File file : sourceDirectory.listFiles())
	{
		String sourceName = file.getName();
		
		sourceName = FilenameUtils.removeExtension(sourceName);
		
		//While associating asmfile to the project, we need to pass the content of the file also, otherwise when 
		//user tries to open the respective file from project explorer, Editor pane will show empty file - Harsha
		SimpleASMFile sourceFile = new SimpleASMFile(project, sourceName, AsmFileContent(file.getAbsolutePath()));
		//SimpleASMFile sourceFile = new SimpleASMFile(project, sourceName);
		project.add(sourceFile);
	}*/
	
	return project;
}