Skip to content

Commit

Permalink
Merge branch 'v2.3' of https://github.com/monkeyWie/proxyee-down into…
Browse files Browse the repository at this point in the history
… v2.3
  • Loading branch information
monkeyWie committed Mar 9, 2018
2 parents 8e652ca + a673ab8 commit b21b4fc
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
54 changes: 49 additions & 5 deletions common/src/main/java/lee/study/down/io/BdyZip.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public static BdyZipEntry getNextFixedBdyZipEntry(FileChannel fileChannel, List<
BdyUnzipCallback callback)
throws IOException {
BdyZipEntry zipEntry = getNextBdyZipEntry(fileChannel);
System.out.println(
ByteUtil.btsToHex(zipEntry.getDate()) + "\t" + ByteUtil.btsToHex(zipEntry.getTime()));
if (!zipEntry.isDir()) {
int index = zipEntry.getFileName().lastIndexOf("/");
if (index != -1) {
Expand Down Expand Up @@ -211,15 +213,30 @@ private static boolean inDirList(List<String> dirList, String dir, boolean tree)
return false;
}
for (String temp : dirList) {
if (dir.matches("^" + temp + "[^/]" + (tree ? "+/" : "*") + "$")) {
if (matchPath(temp, dir, tree)) {
return true;
}
}
return false;
}

private static boolean matchPath(String dir, String path, boolean tree) {
int index = path.indexOf(dir);
if (index == 0) {
String child = path.substring(dir.length());
int count = 0;
for (int i = 0; i < child.length(); i++) {
if (child.charAt(i) == '/') {
count++;
}
}
return tree ? count == 1 : count == 0;
}
return false;
}

public static void unzip(String path, String toPath, BdyUnzipCallback callback)
throws IOException {
throws Exception {
try {
if (callback != null) {
callback.onStart();
Expand Down Expand Up @@ -275,12 +292,39 @@ public static void unzip(String path, String toPath, BdyUnzipCallback callback)


public static void unzip(String path, String toPath)
throws IOException {
throws Exception {
unzip(path, toPath, null);
}

public static void main(String[] args) throws IOException {
unzip(args[0], args[1], new TestUnzipCallback());
public static void main(String[] args) throws Exception {
// unzip(args[0], args[1], new TestUnzipCallback());
// unzip("f:/down/packbu7t.zip","f:/down/packbu7t", new TestUnzipCallback());
FileChannel fileChannel = new RandomAccessFile("f:/down/aaa.zip", "rw")
.getChannel();
ByteBuffer byteBuffer = ByteBuffer.allocate(12);
fileChannel.position(fileChannel.size() - byteBuffer.capacity());
fileChannel.read(byteBuffer);
byteBuffer.flip();
byte[] bts4 = new byte[4];
byte[] bts2 = new byte[2];
byteBuffer.get(bts2);
int entryCount = (int) ByteUtil.btsToNumForSmall(bts2);
byteBuffer.get(bts2);
long centralSize = ByteUtil.btsToNumForSmall(bts2);
ByteBuffer centralBuffer = ByteBuffer.allocate(4);
fileChannel.position(fileChannel.size() - centralSize - 22);
fileChannel.read(centralBuffer);
centralBuffer.flip();
centralBuffer.get(bts4);
System.out.println(ByteUtil.btsToHex(bts4));
/*for (int i = 1; i <= entryCount; i++) {
centralBuffer.clear();
fileChannel.position(fileChannel.size() - (i * centralBuffer.capacity() + 22));
fileChannel.read(centralBuffer);
centralBuffer.flip();
centralBuffer.get(bts4);
System.out.println(ByteUtil.btsToHex(bts4));
}*/
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public void onError(Exception e) {
ContentManager.WS.sendMsg(new WsForm(WsDataType.UNZIP_ING, unzipInfo));
}
});
} catch (IOException e) {
} catch (Exception e) {
LOGGER.error("unzip error:", e);
}
}).start();
Expand Down

0 comments on commit b21b4fc

Please sign in to comment.