當前位置: 首頁>>代碼示例>>Java>>正文


Java ZipFile.getInputStream方法代碼示例

本文整理匯總了Java中net.lingala.zip4j.core.ZipFile.getInputStream方法的典型用法代碼示例。如果您正苦於以下問題:Java ZipFile.getInputStream方法的具體用法?Java ZipFile.getInputStream怎麽用?Java ZipFile.getInputStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.lingala.zip4j.core.ZipFile的用法示例。


在下文中一共展示了ZipFile.getInputStream方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: extract

import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
private byte[] extract(ZipFile zipFile, String file, boolean isFileMandatory) throws ZipException, IOException {
    // Files in the zip are flattened, so remove the folder prefix if there is one
    String fileName = getFileNameFromPath(file);

    // Extract from zip
    FileHeader header = zipFile.getFileHeader(fileName);
    if (header == null) {
        if (isFileMandatory) {
            // Mandatory file not found - throw exception
            throw new IllegalArgumentException(String.format("File %s missing from model run outputs", fileName));
        } else {
            // Optional file not found - return null
            return null;
        }
    } else {
        try (ZipInputStream inputStream = zipFile.getInputStream(header)) {
            return IOUtils.toByteArray(inputStream);
        }
    }
}
 
開發者ID:SEEG-Oxford,項目名稱:ABRAID-MP,代碼行數:21,代碼來源:MainHandler.java

示例2: writeZipEntryBytes

import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
public static void writeZipEntryBytes(File zipFile, String zipEntryPath, OutputStream outputStream)
        throws IOException {
    TFile trueZipFile = new TFile(new File(zipFile, zipEntryPath));
    try {
        try {
            InputStream inputStream;
            if (trueZipFile.isArchive()) {
                synchronizeQuietly(trueZipFile);
                ZipFile internalZipFile = new ZipFile(zipFile);

                inputStream = internalZipFile.getInputStream(internalZipFile.getFileHeader(zipEntryPath));
            } else {
                inputStream = new TFileInputStream(trueZipFile);
            }
            IoUtil.copy(inputStream, outputStream);
        } catch (ZipException e) {
            throw new IOException("Can't write ZIP-entry bytes.", e);
        }
    } finally {
        IoUtil.closeQuietly(outputStream);
        synchronizeQuietly(trueZipFile);
    }
}
 
開發者ID:Codeforces,項目名稱:codeforces-commons,代碼行數:24,代碼來源:ZipUtil.java

示例3: loadMap

import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
/**
 * Tries to load the map data for a name
 *
 * @param name the name of the map to load
 * @return the loaded map
 * @throws MapException when
 */
@Nonnull
public Map loadMap(@Nonnull String name) {
    Optional<Map> map = getMap(name);
    if (!map.isPresent()) {
        Optional<MapInfo> mapInfo = getMapInfo(name);
        if (!mapInfo.isPresent()) {
            throw new MapException(
                    "Unknown map " + name + ". Did you register it into the world config?");
        }

        try {
            ZipFile zipFile = new ZipFile(new File(worldsFolder, mapInfo.get().getName() + ".zip"));
            for (FileHeader header : (List<FileHeader>) zipFile.getFileHeaders()) {
                if (header.getFileName().endsWith("config.json")) {
                    InputStream stream = zipFile.getInputStream(header);
                    Map m = gson.fromJson(new JsonReader(new InputStreamReader(stream)), Map.class);
                    m.initMarkers(mapHandler);
                    maps.add(m);
                    return m;
                }
            }
            throw new MapException("Could not load map config for map " + name
                    + ". Fileheader was null. Does it has a map.json?");

        } catch (Exception e) {
            throw new MapException("Error while trying to load map config " + name, e);
        }
    } else {
        return map.get();
    }
}
 
開發者ID:VoxelGamesLib,項目名稱:VoxelGamesLibv2,代碼行數:39,代碼來源:WorldHandler.java

示例4: getInputStream

import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
public static ZipInputStream getInputStream(File source, String fileName) {
    try {
        ZipFile zipFile = new ZipFile(source);
        return zipFile.getInputStream(zipFile.getFileHeader(fileName));
    } catch (ZipException e) {
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:IzzelAliz,項目名稱:LCL,代碼行數:10,代碼來源:ZipUtils.java

示例5: loadMap

import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
/**
 * Tries to load the map data for a name
 *
 * @param name the name of the map to load
 * @return the loaded map
 * @throws MapException when
 */
@Nonnull
public Map loadMap(@Nonnull String name) {
    Optional<Map> map = getMap(name);
    if (!map.isPresent()) {
        if (!getMapInfo(name).isPresent()) {
            throw new MapException("Unknown map " + name + ". Did you register it into the world config?");
        }

        try {
            ZipFile zipFile = new ZipFile(new File(worldsFolder, name + ".zip"));
            for (FileHeader header : (List<FileHeader>) zipFile.getFileHeaders()) {
                if (header.getFileName().endsWith("config.json")) {
                    InputStream stream = zipFile.getInputStream(header);
                    Map m = gson.fromJson(new JsonReader(new InputStreamReader(stream)), Map.class);
                    maps.add(m);
                    return m;
                }
            }
            throw new MapException("Could not load map config for map " + name + ". Fileheader was null. Does it has a map.json?");

        } catch (Exception e) {
            throw new MapException("Error while trying to load map config " + name, e);
        }
    } else {
        return map.get();
    }
}
 
開發者ID:VoxelGamesLib,項目名稱:VoxelGamesLib,代碼行數:35,代碼來源:WorldHandler.java

示例6: extract

import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
@Override
public InputStream extract(File zip, String fileName, String password) throws ZipException {
    try {
        ZipFile zipFile = new ZipFile(zip);
        if ((password != null) && zipFile.isEncrypted()) {
            zipFile.setPassword(password);
        }
        FileHeader fh = zipFile.getFileHeader(fileName);
        return zipFile.getInputStream(fh);
    } catch (net.lingala.zip4j.exception.ZipException e) {
        throw new ZipException(e);
    }
}
 
開發者ID:brightgenerous,項目名稱:brigen-base,代碼行數:14,代碼來源:ZipDelegaterZip4j.java

示例7: ExtractSelectFilesWithInputStream

import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
public ExtractSelectFilesWithInputStream() {
	
	ZipInputStream is = null;
	OutputStream os = null;
	
	try {
		// Initiate the ZipFile
		ZipFile zipFile = new ZipFile("C:\\ZipTest\\ExtractAllFilesWithInputStreams.zip");
		String destinationPath = "c:\\ZipTest";
		
		// If zip file is password protected then set the password
		if (zipFile.isEncrypted()) {
			zipFile.setPassword("password");
		}
		
		//Get the FileHeader of the File you want to extract from the
		//zip file. Input for the below method is the name of the file
		//For example: 123.txt or abc/123.txt if the file 123.txt
		//is inside the directory abc
		FileHeader fileHeader = zipFile.getFileHeader("yourfilename");
		
		if (fileHeader != null) {
			
			//Build the output file
			String outFilePath = destinationPath + System.getProperty("file.separator") + fileHeader.getFileName();
			File outFile = new File(outFilePath);
			
			//Checks if the file is a directory
			if (fileHeader.isDirectory()) {
				//This functionality is up to your requirements
				//For now I create the directory
				outFile.mkdirs();
				return;
			}
			
			//Check if the directories(including parent directories)
			//in the output file path exists
			File parentDir = outFile.getParentFile();
			if (!parentDir.exists()) {
				parentDir.mkdirs(); //If not create those directories
			}
			
			//Get the InputStream from the ZipFile
			is = zipFile.getInputStream(fileHeader);
			//Initialize the output stream
			os = new FileOutputStream(outFile);
			
			int readLen = -1;
			byte[] buff = new byte[BUFF_SIZE];
			
			//Loop until End of File and write the contents to the output stream
			while ((readLen = is.read(buff)) != -1) {
				os.write(buff, 0, readLen);
			}
			
			//Closing inputstream also checks for CRC of the the just extracted file.
			//If CRC check has to be skipped (for ex: to cancel the unzip operation, etc)
			//use method is.close(boolean skipCRCCheck) and set the flag,
			//skipCRCCheck to false
			//NOTE: It is recommended to close outputStream first because Zip4j throws 
			//an exception if CRC check fails
			is.close();
			
			//Close output stream
			os.close();
			
			//To restore File attributes (ex: last modified file time, 
			//read only flag, etc) of the extracted file, a utility class
			//can be used as shown below
			UnzipUtil.applyFileAttributes(fileHeader, outFile);
			
			System.out.println("Done extracting: " + fileHeader.getFileName());
		} else {
			System.err.println("FileHeader does not exist");
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:joielechong,項目名稱:Zip4jAndroid,代碼行數:80,代碼來源:ExtractSelectFilesWithInputStream.java


注:本文中的net.lingala.zip4j.core.ZipFile.getInputStream方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。