Java Root Path Get getRootFolder(final File file, final String headerFileName)

Here you can find the source of getRootFolder(final File file, final String headerFileName)

Description

get Root Folder

License

Open Source License

Declaration

public static String getRootFolder(final File file, final String headerFileName) throws IOException 

Method Source Code


//package com.java2s;
/*/*from w  w  w  .j a  v a 2s  .co m*/
 * Copyright (C) 2014 by Array Systems Computing Inc. http://www.array.ca
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 3 of the License, or (at your option)
 * any later version.
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, see http://www.gnu.org/licenses/
 */

import java.io.*;
import java.util.Optional;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class Main {
    public static String getRootFolder(final File file, final String headerFileName) throws IOException {
        final ZipFile productZip = new ZipFile(file, ZipFile.OPEN_READ);

        final Optional result = productZip.stream().filter(ze -> !ze.isDirectory())
                .filter(ze -> ze.getName().toLowerCase().endsWith(headerFileName)).findFirst();
        ZipEntry ze = (ZipEntry) result.get();
        String path = ze.toString();
        int sepIndex = path.lastIndexOf('/');
        if (sepIndex > 0) {
            return path.substring(0, sepIndex) + '/';
        } else {
            return "";
        }
    }
}

Related

  1. getRootFloorPlansDir()
  2. getRootFolderPath(File file)
  3. getRootName(File f)
  4. getRootName(String fnm)
  5. getRootName(String pathname)