ZipUtil
public
class
ZipUtil
extends Object
| java.lang.Object
|
| ↳ |
com.android.tradefed.util.ZipUtil
|
압축 관련 작업을 위한 도우미 클래스
요약
공개 메서드 |
static
void
|
addToZip(ZipOutputStream out, File file, List<String> relativePathSegs)
주어진 파일과 그 콘텐츠를 ZipOutputStream에 재귀적으로 추가합니다.
|
static
void
|
applyPermission(File targetFile, CentralDirectoryInfo zipEntry)
중앙 디렉터리 항목에 구성된 파일 권한을 적용합니다.
|
static
void
|
closeZip(ZipFile zipFile)
예외를 무시하고 열려 있는 ZipFile를 닫습니다.
|
static
File
|
createZip(File dir, String name)
지정된 디렉터리와 모든 콘텐츠를 포함하는 임시 ZIP 파일을 만드는 유틸리티 메서드입니다.
|
static
File
|
createZip(File dir)
지정된 디렉터리와 모든 콘텐츠를 포함하는 임시 ZIP 파일을 만드는 유틸리티 메서드입니다.
|
static
File
|
createZip(List<File> files)
지정된 파일이 포함된 임시 zip 파일을 만드는 유틸리티 메서드
|
static
File
|
createZip(List<File> files, String name)
지정된 파일이 포함된 임시 zip 파일을 만드는 유틸리티 메서드입니다.
|
static
void
|
createZip(List<File> files, File zipFile)
지정된 파일이 포함된 zip 파일을 만드는 유틸리티 메서드
|
static
void
|
createZip(File dir, File zipFile)
주어진 디렉터리와 모든 콘텐츠가 포함된 zip 파일을 만드는 유틸리티 메서드입니다.
|
static
File
|
extractFileFromZip(ZipFile zipFile, String filePath)
zip 파일에서 특정 파일을 tmp 파일로 추출하는 유틸리티 메서드
|
static
void
|
extractZip(ZipFile zipFile, File destDir)
지정된 디렉터리에 zip 파일의 전체 콘텐츠를 추출하는 유틸리티 메서드
|
static
void
|
extractZip(ZipFile zipFile, File destDir, Predicate<ZipEntry> shouldExtract)
지정된 디렉터리에 zip 파일의 콘텐츠를 추출하는 유틸리티 메서드
|
static
File
|
extractZipToTemp(File zipFile, String nameHint)
문자열이 앞에 추가된 임시 디렉터리에 zip 파일 추출
|
static
List<CentralDirectoryInfo>
|
getZipCentralDirectoryInfos(File partialZipFile, EndCentralDirectoryInfo endCentralDirInfo, long offset, boolean useZip64)
zip 파일의 파일에 대한 {link CentralDirectoryInfo} 목록을 가져옵니다.
|
static
List<CentralDirectoryInfo>
|
getZipCentralDirectoryInfos(File partialZipFile, EndCentralDirectoryInfo endCentralDirInfo)
zip 파일의 파일에 대한 {link CentralDirectoryInfo} 목록을 가져옵니다.
|
static
List<CentralDirectoryInfo>
|
getZipCentralDirectoryInfos(File partialZipFile, EndCentralDirectoryInfo endCentralDirInfo, boolean useZip64)
zip 파일의 파일에 대한 {link CentralDirectoryInfo} 목록을 가져옵니다.
|
static
List<CentralDirectoryInfo>
|
getZipCentralDirectoryInfos(File partialZipFile, EndCentralDirectoryInfo endCentralDirInfo, long offset)
zip 파일의 파일에 대한 {link CentralDirectoryInfo} 목록을 가져옵니다.
|
static
void
|
gzipFile(File file, File gzipFile)
단일 파일의 gzip 버전을 만드는 도우미 메서드입니다.
|
static
boolean
|
isZipFileValid(File zipFile, boolean thorough)
ZIP 파일이 손상되지 않았는지 확인하는 유틸리티 메서드입니다.
|
static
void
|
unzipPartialZipFile(File partialZip, File targetFile, CentralDirectoryInfo zipEntry, LocalFileHeader localFileHeader, long startOffset)
부분 zip 파일에서 요청된 단일 파일을 추출합니다.
|
static
void
|
unzipPartialZipFolder(File targetFile, CentralDirectoryInfo zipEntry)
부분 ZIP 파일에서 요청된 폴더를 추출하고 적절한 권한을 적용합니다.
|
공개 생성자
ZipUtil
public ZipUtil ()
공개 메서드
addToZip
public static void addToZip (ZipOutputStream out,
File file,
List<String> relativePathSegs)
주어진 파일과 그 콘텐츠를 ZipOutputStream에 재귀적으로 추가합니다.
| 매개변수 |
out |
ZipOutputStream: ZipOutputStream |
file |
File: 스트림에 추가할 File |
relativePathSegs |
List: 구분자를 포함한 파일의 상대 경로 |
| 생성 값 |
IOException |
ZIP에 파일을 추가할 수 없는 경우 |
applyPermission
public static void applyPermission (File targetFile,
CentralDirectoryInfo zipEntry)
중앙 디렉터리 항목에 구성된 파일 권한을 적용합니다.
| 생성 값 |
IOException |
파일에 액세스할 수 없는 경우 |
closeZip
public static void closeZip (ZipFile zipFile)
예외를 무시하고 열려 있는 ZipFile를 닫습니다.
| 매개변수 |
zipFile |
ZipFile: 닫을 파일 |
createZip
public static File createZip (File dir,
String name)
지정된 디렉터리와 모든 콘텐츠를 포함하는 임시 ZIP 파일을 만드는 유틸리티 메서드입니다.
| 매개변수 |
dir |
File: 압축할 디렉터리 |
name |
String: 확장자 없이 생성된 zip 파일의 기본 이름입니다. |
| 반환 |
File |
디렉터리 콘텐츠가 포함된 임시 zip File |
| 생성 값 |
IOException |
ZIP 파일을 만들지 못한 경우 |
createZip
public static File createZip (File dir)
지정된 디렉터리와 모든 콘텐츠를 포함하는 임시 ZIP 파일을 만드는 유틸리티 메서드입니다.
| 반환 |
File |
디렉터리 콘텐츠가 포함된 임시 zip File |
| 생성 값 |
IOException |
ZIP 파일을 만들지 못한 경우 |
createZip
public static File createZip (List<File> files)
지정된 파일이 포함된 임시 zip 파일을 만드는 유틸리티 메서드
| 매개변수 |
files |
List: 압축할 파일 목록 |
| 반환 |
File |
디렉터리 콘텐츠가 포함된 임시 zip File |
| 생성 값 |
IOException |
ZIP 파일을 만들지 못한 경우 |
createZip
public static File createZip (List<File> files,
String name)
지정된 파일이 포함된 임시 zip 파일을 만드는 유틸리티 메서드입니다.
| 매개변수 |
files |
List: 압축할 파일 목록 |
name |
String: 확장자 없이 생성된 zip 파일의 기본 이름입니다. |
| 반환 |
File |
디렉터리 콘텐츠가 포함된 임시 zip File |
| 생성 값 |
IOException |
ZIP 파일을 만들지 못한 경우 |
createZip
public static void createZip (List<File> files,
File zipFile)
지정된 파일이 포함된 zip 파일을 만드는 유틸리티 메서드
| 매개변수 |
files |
List: 압축할 파일 목록 |
zipFile |
File: 생성할 zip 파일입니다. 아직 존재하지 않아야 합니다. |
| 생성 값 |
IOException |
ZIP 파일을 만들지 못한 경우 |
createZip
public static void createZip (File dir,
File zipFile)
주어진 디렉터리와 모든 콘텐츠가 포함된 zip 파일을 만드는 유틸리티 메서드입니다.
| 매개변수 |
dir |
File: 압축할 디렉터리 |
zipFile |
File: 생성할 zip 파일입니다. 아직 존재하지 않아야 합니다. |
| 생성 값 |
IOException |
ZIP 파일을 만들지 못한 경우 |
public static File extractFileFromZip (ZipFile zipFile,
String filePath)
zip 파일에서 특정 파일을 tmp 파일로 추출하는 유틸리티 메서드
| 매개변수 |
zipFile |
ZipFile: 추출할 ZipFile |
filePath |
String: 추출할 파일 경로 |
| 반환 |
File |
File 또는 찾을 수 없는 경우 null |
| 생성 값 |
IOException |
파일 추출에 실패한 경우 |
public static void extractZip (ZipFile zipFile,
File destDir)
지정된 디렉터리에 zip 파일의 전체 콘텐츠를 추출하는 유틸리티 메서드
| 매개변수 |
zipFile |
ZipFile: 추출할 ZipFile |
destDir |
File: 파일을 추출할 로컬 디렉터리 |
| 생성 값 |
IOException |
파일 추출에 실패한 경우 |
public static void extractZip (ZipFile zipFile,
File destDir,
Predicate<ZipEntry> shouldExtract)
지정된 디렉터리에 zip 파일의 콘텐츠를 추출하는 유틸리티 메서드
| 매개변수 |
zipFile |
ZipFile: 추출할 ZipFile |
destDir |
File: 파일을 추출할 로컬 디렉터리 |
shouldExtract |
Predicate: ZipEntry를 추출해야 하는지 여부를 결정하는 조건자 |
| 생성 값 |
IOException |
파일 추출에 실패한 경우 |
public static File extractZipToTemp (File zipFile,
String nameHint)
문자열이 앞에 추가된 임시 디렉터리에 zip 파일 추출
| 매개변수 |
zipFile |
File: 추출할 zip 파일 |
nameHint |
String: 임시 디렉터리의 접두사 |
| 반환 |
File |
임시 디렉터리를 가리키는 File |
| 생성 값 |
IOException |
|
ZipException |
|
getZipCentralDirectoryInfos
public static List<CentralDirectoryInfo> getZipCentralDirectoryInfos (File partialZipFile,
EndCentralDirectoryInfo endCentralDirInfo,
long offset,
boolean useZip64)
zip 파일의 파일에 대한 {link CentralDirectoryInfo} 목록을 가져옵니다.
| 매개변수 |
partialZipFile |
File: 중앙 디렉터리 항목이 포함된 부분 ZIP 파일의 File 객체입니다. |
endCentralDirInfo |
EndCentralDirectoryInfo: zip 파일의 EndCentralDirectoryInfo 객체입니다. |
offset |
long: 중앙 디렉터리 항목의 콘텐츠가 시작되는 부분 ZIP 파일의 오프셋입니다. |
useZip64 |
boolean: 부분 다운로드에서 zip64 형식을 지원하는 불리언입니다. |
| 생성 값 |
|
java.io.IOException |
IOException |
|
getZipCentralDirectoryInfos
public static List<CentralDirectoryInfo> getZipCentralDirectoryInfos (File partialZipFile,
EndCentralDirectoryInfo endCentralDirInfo)
zip 파일의 파일에 대한 {link CentralDirectoryInfo} 목록을 가져옵니다.
| 매개변수 |
partialZipFile |
File: 중앙 디렉터리 항목이 포함된 부분 ZIP 파일의 File 객체입니다. |
endCentralDirInfo |
EndCentralDirectoryInfo: zip 파일의 EndCentralDirectoryInfo 객체입니다. |
| 생성 값 |
|
java.io.IOException |
IOException |
|
getZipCentralDirectoryInfos
public static List<CentralDirectoryInfo> getZipCentralDirectoryInfos (File partialZipFile,
EndCentralDirectoryInfo endCentralDirInfo,
boolean useZip64)
zip 파일의 파일에 대한 {link CentralDirectoryInfo} 목록을 가져옵니다.
| 매개변수 |
partialZipFile |
File: 중앙 디렉터리 항목이 포함된 부분 ZIP 파일의 File 객체입니다. |
endCentralDirInfo |
EndCentralDirectoryInfo: zip 파일의 EndCentralDirectoryInfo 객체입니다. |
useZip64 |
boolean: 부분 다운로드에서 zip64 형식을 지원하는 불리언입니다. |
| 생성 값 |
|
java.io.IOException |
IOException |
|
getZipCentralDirectoryInfos
public static List<CentralDirectoryInfo> getZipCentralDirectoryInfos (File partialZipFile,
EndCentralDirectoryInfo endCentralDirInfo,
long offset)
zip 파일의 파일에 대한 {link CentralDirectoryInfo} 목록을 가져옵니다.
| 매개변수 |
partialZipFile |
File: 중앙 디렉터리 항목이 포함된 부분 ZIP 파일의 File 객체입니다. |
endCentralDirInfo |
EndCentralDirectoryInfo: zip 파일의 EndCentralDirectoryInfo 객체입니다. |
offset |
long: 중앙 디렉터리 항목의 콘텐츠가 시작되는 부분 ZIP 파일의 오프셋입니다. |
| 생성 값 |
|
java.io.IOException |
IOException |
|
gzipFile
public static void gzipFile (File file,
File gzipFile)
단일 파일의 gzip 버전을 만드는 도우미 메서드입니다.
| 매개변수 |
file |
File: 원본 파일 |
gzipFile |
File: 압축된 콘텐츠를 배치할 파일 |
| 생성 값 |
|
java.io.IOException |
IOException |
|
isZipFileValid
public static boolean isZipFileValid (File zipFile,
boolean thorough)
ZIP 파일이 손상되지 않았는지 확인하는 유틸리티 메서드입니다.
| 매개변수 |
zipFile |
File: 확인할 File |
thorough |
boolean: 보관 파일을 완전히 추출할지 여부입니다. false인 경우 이 메서드는 형식이 올바른 보관 파일에서 CRC 오류를 감지하지 못합니다. |
| 반환 |
boolean |
파일이 손상된 것으로 보이는 경우 false, 그렇지 않은 경우 true |
| 생성 값 |
IOException |
파일을 열거나 읽을 수 없는 경우 |
unzipPartialZipFile
public static void unzipPartialZipFile (File partialZip,
File targetFile,
CentralDirectoryInfo zipEntry,
LocalFileHeader localFileHeader,
long startOffset)
부분 zip 파일에서 요청된 단일 파일을 추출합니다.
이 방법은 압축 시 모든 파일이 동일한 디스크에 있다고 가정합니다.
ERROR(/targetFile)가 디렉터리인 경우 콘텐츠 없이 빈 디렉터리가 생성됩니다.
ERROR(/targetFile)가 심볼릭 링크인 경우 심볼릭 링크가 생성되지만 확인되지는 않습니다.
다음 기능은 아직 지원되지 않습니다.
ZIP 파일이 4GB보다 큼
ZIP64(압축된 크기에 ZipLocalFileHeader 업데이트 필요)
암호화된 ZIP 파일
| 매개변수 |
partialZip |
File: ZIP 파일의 일부인 File입니다. |
targetFile |
File: 추출된 파일을 저장할 File입니다. |
zipEntry |
CentralDirectoryInfo: 부분 zip 파일에서 추출할 파일의 CentralDirectoryInfo 객체입니다. |
localFileHeader |
LocalFileHeader: 부분 zip 파일에서 추출할 파일의 LocalFileHeader 객체입니다. |
startOffset |
long: 추출할 파일의 시작 오프셋입니다. |
| 생성 값 |
|
java.io.IOException |
IOException |
|
unzipPartialZipFolder
public static void unzipPartialZipFolder (File targetFile,
CentralDirectoryInfo zipEntry)
부분 ZIP 파일에서 요청된 폴더를 추출하고 적절한 권한을 적용합니다.
| 매개변수 |
targetFile |
File: 추출된 파일을 저장할 File입니다. |
zipEntry |
CentralDirectoryInfo: 부분 zip 파일에서 추출할 파일의 CentralDirectoryInfo 객체입니다. |
| 생성 값 |
|
java.io.IOException |
IOException |
|
보호된 메서드
validateDestinationDir
protected static void validateDestinationDir (File destDir,
String filename)
| 매개변수 |
destDir |
File |
filename |
String |