fixed bug with computing MD5 hash and multithreading
This commit is contained in:
@@ -1,17 +1,24 @@
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import org.jpacrepo.model.PkgData;
|
||||
import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
|
||||
import org.jboss.resteasy.plugins.providers.jackson.ResteasyJacksonProvider;
|
||||
import org.jboss.resteasy.spi.ResteasyProviderFactory;
|
||||
import org.jpacrepo.model.PkgData;
|
||||
import org.jpacrepo.pacbase.Hasher;
|
||||
import org.jpacrepo.pacbase.MD5InputStream;
|
||||
import org.jpacrepo.pacbase.Parser;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.ws.rs.client.*;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriBuilder;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.DigestInputStream;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
/**
|
||||
* Created by walter on 29/03/15.
|
||||
@@ -57,4 +64,39 @@ public class ClientTest
|
||||
System.out.println(response.getStatusInfo());
|
||||
assert Response.Status.CREATED.getStatusCode() == response.getStatus();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashTest() throws Exception
|
||||
{
|
||||
String[] files = new String[]{"/var/cache/pacman/pkg/mesa-10.4.5-1-x86_64.pkg.tar.xz", "/var/cache/pacman/pkg/mesa-10.5.3-1-x86_64.pkg.tar.xz"};
|
||||
|
||||
for (String file : files)
|
||||
{
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
try (InputStream is = Files.newInputStream(Paths.get(file)))
|
||||
{
|
||||
DigestInputStream dis = new DigestInputStream(is, md);
|
||||
dis.on(true);
|
||||
// is.read();
|
||||
long a = new File(file).length();
|
||||
byte[] out = new byte[(int)a];
|
||||
dis.read(out, 0, (int) a);
|
||||
}
|
||||
System.out.println(Hasher.bytesToHex(md.digest()));
|
||||
|
||||
System.out.println(Hasher.computeMD5(new FileInputStream(file)));
|
||||
|
||||
InputStream fis = new FileInputStream(file);
|
||||
MD5InputStream h = Hasher.createMD5InputStream(fis);
|
||||
long a = new File(file).length();
|
||||
byte[] out = new byte[(int)a];
|
||||
h.read(out, 0, (int) a);
|
||||
System.out.println(h.digest());
|
||||
|
||||
PkgData p = new Parser().parseFile(new File(file));
|
||||
System.out.println(p.md5sum);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,23 +1,26 @@
|
||||
import org.jpacrepo.model.PkgData;
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.filefilter.DirectoryFileFilter;
|
||||
import org.apache.commons.io.filefilter.RegexFileFilter;
|
||||
import org.junit.Test;
|
||||
import org.jpacrepo.model.PkgData;
|
||||
import org.jpacrepo.pacbase.Parser;
|
||||
import org.jpacrepo.service.PacmanService;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.naming.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Created by walter on 22/03/15.
|
||||
*/
|
||||
public class ParseTest
|
||||
{
|
||||
// @Test
|
||||
// @Test
|
||||
public void test() throws Exception
|
||||
{
|
||||
|
||||
@@ -26,7 +29,7 @@ public class ParseTest
|
||||
List<PkgData> lista = new ArrayList<>();
|
||||
for (File file : ls)
|
||||
{
|
||||
PkgData data = Parser.parseFile(file);
|
||||
PkgData data = new Parser().parseFile(file);
|
||||
lista.add(data);
|
||||
//System.out.println(new XStream().toXML(data));
|
||||
// if(i++>10) break;
|
||||
@@ -59,16 +62,32 @@ public class ParseTest
|
||||
stateService.deletePackage("linux-3.19.3-3-x86_64.pkg.tar.xz");
|
||||
}
|
||||
|
||||
private static void traverseJndiNode(String nodeName, Context context) {
|
||||
try {
|
||||
private static void traverseJndiNode(String nodeName, Context context)
|
||||
{
|
||||
try
|
||||
{
|
||||
NamingEnumeration<NameClassPair> list = context.list(nodeName);
|
||||
while (list.hasMore()){
|
||||
while (list.hasMore())
|
||||
{
|
||||
String childName = nodeName + "" + list.next().getName();
|
||||
System.out.println(childName);
|
||||
traverseJndiNode(childName, context);
|
||||
}
|
||||
} catch (NamingException ex) {
|
||||
} catch (NamingException ex)
|
||||
{
|
||||
// We reached a leaf
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseTest() throws Exception
|
||||
{
|
||||
String[] files = new String[]{"/var/cache/pacman/pkg/mesa-10.4.5-1-x86_64.pkg.tar.xz", "/var/cache/pacman/pkg/mesa-10.5.3-1-x86_64.pkg.tar.xz"};
|
||||
|
||||
for (String file : files)
|
||||
{
|
||||
PkgData data = new Parser().parseFile(new File(file));
|
||||
System.out.println(new XStream().toXML(data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user