Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Options:
hfs, gzip, cpio, bzip2, 7z, z, arj, cab, lzh, chm, nsis,
ar, rpm, udf, wim, xar, fat, ntfs
/a -a archive filename or URL location of archive
/p -p password for the archive
/e -e filename to extract out of the archive
/l -l list content of archive
/o -o output filename for the extracted file
Expand Down
37 changes: 24 additions & 13 deletions src/readsevenzip/HttpIsoReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ private static void usage() {
}

System.out.println(" /a -a archive filename or URL location of archive");
System.out.println(" /p -p password for the archive");
System.out.println(" /e -e filename to extract out of the archive");
System.out.println(" /l -l list content of archive");
System.out.println(" /o -o output filename for the extracted file");
Expand All @@ -82,35 +83,36 @@ private static void usage() {
}

public Boolean open(String URL) {
return open(URL, null);
return open(URL, null, null);
}

public Boolean open(String URL, ArchiveFormat type) {
public Boolean open(String URL, ArchiveFormat type, String password) {
try {
archive = SevenZip.openInArchive(type, new MonitorIInStream(new HttpIInStream(URL)));
archive = SevenZip.openInArchive(type, new MonitorIInStream(new HttpIInStream(URL)), password);
return true;
} catch (Exception ex) {
return false;
}
}

public Boolean open(File file) {
return open(file, null);
return open(file, null, null);
}

public Boolean open(File file, ArchiveFormat type) {
public Boolean open(File file, ArchiveFormat type, String password) {
try {
archive = SevenZip.openInArchive(type,
new MonitorIInStream(
new RandomAccessFileInStream(
new RandomAccessFile(file, "r"))));
new RandomAccessFile(file, "r"))),
password);
return true;
} catch (Exception ex) {
return false;
}
}

public void getFile(String sourceFilePath, String targetFilePath) throws IOException, SevenZipException {
public void getFile(String sourceFilePath, String targetFilePath, String password) throws IOException, SevenZipException {

File f = new File(targetFilePath);
final FileOutputStream fos = new FileOutputStream(f);
Expand All @@ -127,7 +129,7 @@ public void getFile(String sourceFilePath, String targetFilePath) throws IOExcep
final long[] sizeArray = new long[1];
final Long size = item.getSize();

result = item.extractSlow(new ISequentialOutStream() {
ISequentialOutStream outStream = new ISequentialOutStream() {

long loaded = 0;

Expand All @@ -146,7 +148,13 @@ public int write(byte[] data) throws SevenZipException {
throw new SevenZipException(ex);
}
}
});
};

if (password == null)
result = item.extractSlow(outStream);
else
result = item.extractSlow(outStream, password);

if (result == ExtractOperationResult.OK) {
fos.flush();
fos.close();
Expand Down Expand Up @@ -202,6 +210,7 @@ public static void main(String[] a) throws Exception {
String archive_filename = null;
String archive_type_arg;
ArchiveFormat archive_type = null;
String password = null;
String extract_filename = null;
String output_filename = null;
boolean list_archive_content = false;
Expand All @@ -226,6 +235,8 @@ public static void main(String[] a) throws Exception {
}
} else if (arg_lower.startsWith("/a=") || arg_lower.startsWith("-a=")) {
archive_filename = arg.substring(3);
} else if (arg_lower.startsWith("/p=") || arg_lower.startsWith("-p=")) {
password = arg.substring(3);
} else if (arg_lower.startsWith("/e=") || arg_lower.startsWith("-e=")) {
extract_filename = arg.substring(3);
} else if (arg_lower.equals("/l") || arg_lower.equals("-l")) {
Expand Down Expand Up @@ -255,14 +266,14 @@ public static void main(String[] a) throws Exception {
Boolean result = false;
if (archive_filename.toLowerCase().startsWith("http://")) {
System.out.println("Opening HTTP archive '" + archive_filename + "'.");
result = reader.open(archive_filename, archive_type);
result = reader.open(archive_filename, archive_type, password);
} else if (archive_filename.toLowerCase().startsWith("https://")) {
System.out.println("Opening HTTPS archive '" + archive_filename + "'.");
result = reader.open(archive_filename, archive_type);
result = reader.open(archive_filename, archive_type, password);
} else {
System.out.println("Opening FILE archive '" + archive_filename + "'.");
try {
result = reader.open(new File(archive_filename), archive_type);
result = reader.open(new File(archive_filename), archive_type, password);
}
catch(Exception e){
System.out.println("Invalid '" + archive_type + "' file '" + archive_filename + "'.");
Expand Down Expand Up @@ -301,7 +312,7 @@ public static void main(String[] a) throws Exception {
System.out.println("Extracting file '" + extract_filename + "' ...");

try {
reader.getFile(extract_filename, output_filename);
reader.getFile(extract_filename, output_filename, password);
reader.close();
}
catch(Exception e){
Expand Down