List of usage examples for java.util Hashtable size
public synchronized int size()
From source file:algorithm.OpenStegoRandomLSBSteganographyTest.java
@Test public void openStegoRandomLsbSteganographyAlgorithmTest() { try {/* w ww. java 2 s. co m*/ File carrier = TestDataProvider.PNG_FILE; File payload = TestDataProvider.TXT_FILE; OpenStegoRandomLSBSteganography algorithm = new OpenStegoRandomLSBSteganography(); // Test encapsulation: List<File> payloadList = new ArrayList<File>(); payloadList.add(payload); File outputFile = algorithm.encapsulate(carrier, payloadList); assertNotNull(outputFile); // Test restore: Hashtable<String, RestoredFile> outputHash = new Hashtable<String, RestoredFile>(); for (RestoredFile file : algorithm.restore(outputFile)) { outputHash.put(file.getName(), file); } assertEquals(outputHash.size(), 2); RestoredFile restoredCarrier = outputHash.get(carrier.getName()); RestoredFile restoredPayload = outputHash.get(payload.getName()); assertNotNull(restoredCarrier); assertNotNull(restoredPayload); // can only restore original payload with this algorithm, not // carrier! assertEquals(FileUtils.checksumCRC32(payload), FileUtils.checksumCRC32(restoredPayload)); // check restoration metadata: assertEquals("" + carrier.getAbsolutePath(), restoredCarrier.originalFilePath); assertEquals("" + payload.getAbsolutePath(), restoredPayload.originalFilePath); assertEquals(algorithm, restoredCarrier.algorithm); // This can't be true for steganography algorithms: // assertTrue(restoredCarrier.checksumValid); assertTrue(restoredPayload.checksumValid); assertTrue(restoredCarrier.wasCarrier); assertFalse(restoredCarrier.wasPayload); assertTrue(restoredPayload.wasPayload); assertFalse(restoredPayload.wasCarrier); assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload)); assertFalse(restoredCarrier.relatedFiles.contains(restoredCarrier)); assertTrue(restoredPayload.relatedFiles.contains(restoredCarrier)); assertFalse(restoredPayload.relatedFiles.contains(restoredPayload)); } catch (IOException e) { e.printStackTrace(); } }
From source file:algorithm.ZipPackagingTest.java
@Test public void zipPackagingTest() { try {//from w w w .ja v a 2 s. co m File carrier = TestDataProvider.TXT_FILE; File payload1 = TestDataProvider.TXT_FILE_2; File payload2 = TestDataProvider.XML_FILE; List<File> payloadList = new ArrayList<File>(); payloadList.add(payload1); payloadList.add(payload2); ZipPackaging algorithm = new ZipPackaging(); // Test encapsulation: File outputFile = algorithm.encapsulate(carrier, payloadList); assertNotNull(outputFile); // Test restore: Hashtable<String, RestoredFile> outputHash = new Hashtable<String, RestoredFile>(); for (RestoredFile file : algorithm.restore(outputFile)) { outputHash.put(file.getName(), file); } assertEquals(3, outputHash.size()); RestoredFile restoredCarrier = outputHash.get(carrier.getName()); RestoredFile restoredPayload1 = outputHash.get(payload1.getName()); RestoredFile restoredPayload2 = outputHash.get(payload2.getName()); assertNotNull(restoredCarrier); assertNotNull(restoredPayload1); assertNotNull(restoredPayload2); assertEquals(FileUtils.checksumCRC32(carrier), FileUtils.checksumCRC32(restoredCarrier)); assertEquals(FileUtils.checksumCRC32(payload1), FileUtils.checksumCRC32(restoredPayload1)); assertEquals(FileUtils.checksumCRC32(payload2), FileUtils.checksumCRC32(restoredPayload2)); // check restoration metadata: // (algorithm doesn't save original file paths) assertEquals(algorithm, restoredCarrier.algorithm); assertTrue(restoredCarrier.checksumValid); assertTrue(restoredPayload1.checksumValid); assertTrue(restoredPayload2.checksumValid); // every file in a zip package is payload!: assertTrue(restoredCarrier.wasPayload); assertFalse(restoredCarrier.wasCarrier); assertTrue(restoredPayload1.wasPayload); assertFalse(restoredPayload1.wasCarrier); assertTrue(restoredPayload2.wasPayload); assertFalse(restoredPayload2.wasCarrier); assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload1)); assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload2)); assertFalse(restoredCarrier.relatedFiles.contains(restoredCarrier)); assertTrue(restoredPayload1.relatedFiles.contains(restoredCarrier)); assertTrue(restoredPayload1.relatedFiles.contains(restoredPayload2)); assertFalse(restoredPayload1.relatedFiles.contains(restoredPayload1)); } catch (IOException e) { e.printStackTrace(); } }
From source file:algorithm.BagItPackagingTest.java
@Test public void bagItPackagingTest() { try {//w w w . ja v a2 s. com File carrier = TestDataProvider.TXT_FILE; File payload1 = TestDataProvider.TXT_FILE_2; File payload2 = TestDataProvider.XML_FILE; List<File> payloadList = new ArrayList<File>(); payloadList.add(payload1); payloadList.add(payload2); BagItPackaging algorithm = new BagItPackaging(); // Test encapsulation: File outputFile = algorithm.encapsulate(carrier, payloadList); assertNotNull(outputFile); assertTrue(outputFile.length() > carrier.length()); // Test restore: Hashtable<String, RestoredFile> outputHash = new Hashtable<String, RestoredFile>(); for (RestoredFile file : algorithm.restore(outputFile)) { outputHash.put(file.getName(), file); } assertEquals(3, outputHash.size()); RestoredFile restoredCarrier = outputHash.get(carrier.getName()); RestoredFile restoredPayload1 = outputHash.get(payload1.getName()); RestoredFile restoredPayload2 = outputHash.get(payload2.getName()); assertNotNull(restoredCarrier); assertNotNull(restoredPayload1); assertNotNull(restoredPayload2); assertEquals(FileUtils.checksumCRC32(carrier), FileUtils.checksumCRC32(restoredCarrier)); assertEquals(FileUtils.checksumCRC32(payload1), FileUtils.checksumCRC32(restoredPayload1)); assertEquals(FileUtils.checksumCRC32(payload2), FileUtils.checksumCRC32(restoredPayload2)); // check restoration metadata: // (original file paths are not stored with BagIt) assertEquals(algorithm, restoredCarrier.algorithm); assertTrue(restoredCarrier.checksumValid); assertTrue(restoredPayload1.checksumValid); assertTrue(restoredPayload2.checksumValid); assertTrue(restoredCarrier.wasCarrier); assertFalse(restoredCarrier.wasPayload); assertTrue(restoredPayload1.wasPayload); assertFalse(restoredPayload1.wasCarrier); assertTrue(restoredPayload2.wasPayload); assertFalse(restoredPayload2.wasCarrier); assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload1)); assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload2)); assertFalse(restoredCarrier.relatedFiles.contains(restoredCarrier)); assertTrue(restoredPayload1.relatedFiles.contains(restoredCarrier)); assertTrue(restoredPayload1.relatedFiles.contains(restoredPayload2)); assertFalse(restoredPayload1.relatedFiles.contains(restoredPayload1)); } catch (IOException e) { e.printStackTrace(); } }
From source file:algorithm.MetsSubmissionInformationPackageTest.java
@Test public void MetsSipTest() { try {/* ww w.ja v a2s . c om*/ File carrier = TestDataProvider.TXT_FILE; File payload1 = TestDataProvider.TXT_FILE_2; File payload2 = TestDataProvider.XML_FILE; List<File> payloadList = new ArrayList<File>(); payloadList.add(payload1); payloadList.add(payload2); MetsSubmissionInformationPackage algorithm = new MetsSubmissionInformationPackage(); // Test encapsulation: File outputFile = algorithm.encapsulate(carrier, payloadList); assertNotNull(outputFile); assertTrue(outputFile.length() > carrier.length()); // Test restore: Hashtable<String, RestoredFile> outputHash = new Hashtable<String, RestoredFile>(); for (RestoredFile file : algorithm.restore(outputFile)) { outputHash.put(file.getName(), file); } assertEquals(4, outputHash.size());// files+map! RestoredFile restoredCarrier = outputHash.get(carrier.getName()); RestoredFile restoredPayload1 = outputHash.get(payload1.getName()); RestoredFile restoredPayload2 = outputHash.get(payload2.getName()); assertNotNull(restoredCarrier); assertNotNull(restoredPayload1); assertNotNull(restoredPayload2); assertEquals(FileUtils.checksumCRC32(carrier), FileUtils.checksumCRC32(restoredCarrier)); assertEquals(FileUtils.checksumCRC32(payload1), FileUtils.checksumCRC32(restoredPayload1)); assertEquals(FileUtils.checksumCRC32(payload2), FileUtils.checksumCRC32(restoredPayload2)); // check restoration metadata: assertEquals(algorithm, restoredCarrier.algorithm); assertTrue(restoredCarrier.checksumValid); assertTrue(restoredPayload1.checksumValid); assertTrue(restoredPayload2.checksumValid); // every file in a zip package is payload!: assertTrue(restoredCarrier.wasPayload); assertFalse(restoredCarrier.wasCarrier); assertTrue(restoredPayload1.wasPayload); assertFalse(restoredPayload1.wasCarrier); assertTrue(restoredPayload2.wasPayload); assertFalse(restoredPayload2.wasCarrier); assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload1)); assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload2)); assertFalse(restoredCarrier.relatedFiles.contains(restoredCarrier)); assertTrue(restoredPayload1.relatedFiles.contains(restoredCarrier)); assertTrue(restoredPayload1.relatedFiles.contains(restoredPayload2)); assertFalse(restoredPayload1.relatedFiles.contains(restoredPayload1)); } catch (IOException e) { e.printStackTrace(); } }
From source file:algorithm.OaiOreSubmissionInformationPackageTest.java
@Test public void OaiOreSipTest() { try {/*www . ja v a 2 s . co m*/ File carrier = TestDataProvider.TXT_FILE; File payload1 = TestDataProvider.TXT_FILE_2; File payload2 = TestDataProvider.XML_FILE; List<File> payloadList = new ArrayList<File>(); payloadList.add(payload1); payloadList.add(payload2); OaiOreSubmissionInformationPackage algorithm = new OaiOreSubmissionInformationPackage(); // Test encapsulation: File outputFile = algorithm.encapsulate(carrier, payloadList); assertNotNull(outputFile); assertTrue(outputFile.length() > carrier.length()); // Test restore: Hashtable<String, RestoredFile> outputHash = new Hashtable<String, RestoredFile>(); for (RestoredFile file : algorithm.restore(outputFile)) { outputHash.put(file.getName(), file); } assertEquals(4, outputHash.size());// files+map! RestoredFile restoredCarrier = outputHash.get(carrier.getName()); RestoredFile restoredPayload1 = outputHash.get(payload1.getName()); RestoredFile restoredPayload2 = outputHash.get(payload2.getName()); assertNotNull(restoredCarrier); assertNotNull(restoredPayload1); assertNotNull(restoredPayload2); assertEquals(FileUtils.checksumCRC32(carrier), FileUtils.checksumCRC32(restoredCarrier)); assertEquals(FileUtils.checksumCRC32(payload1), FileUtils.checksumCRC32(restoredPayload1)); assertEquals(FileUtils.checksumCRC32(payload2), FileUtils.checksumCRC32(restoredPayload2)); // check restoration metadata: assertEquals(algorithm, restoredCarrier.algorithm); assertTrue(restoredCarrier.checksumValid); assertTrue(restoredPayload1.checksumValid); assertTrue(restoredPayload2.checksumValid); // every file in a zip package is payload!: assertTrue(restoredCarrier.wasPayload); assertFalse(restoredCarrier.wasCarrier); assertTrue(restoredPayload1.wasPayload); assertFalse(restoredPayload1.wasCarrier); assertTrue(restoredPayload2.wasPayload); assertFalse(restoredPayload2.wasCarrier); assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload1)); assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload2)); assertFalse(restoredCarrier.relatedFiles.contains(restoredCarrier)); assertTrue(restoredPayload1.relatedFiles.contains(restoredCarrier)); assertTrue(restoredPayload1.relatedFiles.contains(restoredPayload2)); assertFalse(restoredPayload1.relatedFiles.contains(restoredPayload1)); } catch (IOException e) { e.printStackTrace(); } }
From source file:algorithm.PNGChunkAddingTest.java
@Test public void pngMultipleChunkAddingTest() { try {/* w w w .ja v a2s.c o m*/ File carrier = TestDataProvider.PNG_FILE; File payload = TestDataProvider.TXT_FILE; File payload2 = TestDataProvider.TXT_FILE_2; List<File> payloadList = new ArrayList<File>(); payloadList.add(payload); payloadList.add(payload2); PNGChunkAdding algorithm = new PNGChunkAdding(); // Test encapsulation: File outputFile = algorithm.encapsulate(carrier, payloadList); assertNotNull(outputFile); // Test restore: Hashtable<String, RestoredFile> outputHash = new Hashtable<String, RestoredFile>(); for (RestoredFile file : algorithm.restore(outputFile)) { outputHash.put(file.getName(), file); } assertEquals(3, outputHash.size()); RestoredFile restoredCarrier = outputHash.get(carrier.getName()); RestoredFile restoredPayload = outputHash.get(payload.getName()); RestoredFile restoredPayload2 = outputHash.get(payload2.getName()); assertNotNull(restoredCarrier); assertNotNull(restoredPayload); assertNotNull(restoredPayload2); // TODO: The carrier checksum is not valid, because the PNG library // reorders the chunks! We would have to use a different library. // assertEquals(FileUtils.checksumCRC32(carrier), // FileUtils.checksumCRC32(restoredCarrier)); assertEquals(FileUtils.checksumCRC32(payload), FileUtils.checksumCRC32(restoredPayload)); assertEquals(FileUtils.checksumCRC32(payload2), FileUtils.checksumCRC32(restoredPayload2)); // check restoration metadata: assertEquals("" + carrier.getAbsolutePath(), restoredCarrier.originalFilePath); assertEquals("" + payload.getAbsolutePath(), restoredPayload.originalFilePath); assertEquals(algorithm, restoredCarrier.algorithm); // can't be true for this algorithm: // assertTrue(restoredCarrier.checksumValid); assertTrue(restoredPayload.checksumValid); assertTrue(restoredCarrier.wasCarrier); assertFalse(restoredCarrier.wasPayload); assertTrue(restoredPayload.wasPayload); assertFalse(restoredPayload.wasCarrier); assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload)); assertFalse(restoredCarrier.relatedFiles.contains(restoredCarrier)); assertTrue(restoredPayload.relatedFiles.contains(restoredCarrier)); assertFalse(restoredPayload.relatedFiles.contains(restoredPayload)); } catch (IOException e) { e.printStackTrace(); } }
From source file:algorithm.TxtInformationFrameTest.java
@Test public void textInformationFrameAlgorithmTest() { try {//from w w w . ja v a 2 s. c om File carrier = TestDataProvider.TXT_FILE; File payload1 = TestDataProvider.TXT_FILE_2; File payload2 = TestDataProvider.XML_FILE; List<File> payloadList = new ArrayList<File>(); payloadList.add(payload1); payloadList.add(payload2); TextInformationFrame algorithm = new TextInformationFrame(); // Test encapsulation: File outputFile = algorithm.encapsulate(carrier, payloadList); assertNotNull(outputFile); assertTrue(outputFile.length() > carrier.length()); // Test restore: Hashtable<String, RestoredFile> outputHash = new Hashtable<String, RestoredFile>(); for (RestoredFile file : algorithm.restore(outputFile)) { outputHash.put(file.getName(), file); } assertEquals(3, outputHash.size()); RestoredFile restoredCarrier = outputHash.get(carrier.getName()); RestoredFile restoredPayload1 = outputHash.get(payload1.getName()); RestoredFile restoredPayload2 = outputHash.get(payload2.getName()); assertNotNull(restoredCarrier); assertNotNull(restoredPayload1); assertNotNull(restoredPayload2); assertEquals(FileUtils.checksumCRC32(carrier), FileUtils.checksumCRC32(restoredCarrier)); assertEquals(FileUtils.checksumCRC32(payload1), FileUtils.checksumCRC32(restoredPayload1)); assertEquals(FileUtils.checksumCRC32(payload2), FileUtils.checksumCRC32(restoredPayload2)); // check restoration metadata: assertEquals("" + carrier.getAbsolutePath(), restoredCarrier.originalFilePath); assertEquals("" + payload1.getAbsolutePath(), restoredPayload1.originalFilePath); assertEquals("" + payload2.getAbsolutePath(), restoredPayload2.originalFilePath); assertEquals(algorithm, restoredCarrier.algorithm); assertTrue(restoredCarrier.checksumValid); assertTrue(restoredPayload1.checksumValid); assertTrue(restoredPayload2.checksumValid); assertTrue(restoredCarrier.wasCarrier); assertFalse(restoredCarrier.wasPayload); assertTrue(restoredPayload1.wasPayload); assertFalse(restoredPayload1.wasCarrier); assertTrue(restoredPayload2.wasPayload); assertFalse(restoredPayload2.wasCarrier); assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload1)); assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload2)); assertFalse(restoredCarrier.relatedFiles.contains(restoredCarrier)); assertTrue(restoredPayload1.relatedFiles.contains(restoredCarrier)); assertTrue(restoredPayload1.relatedFiles.contains(restoredPayload2)); assertFalse(restoredPayload1.relatedFiles.contains(restoredPayload1)); } catch (IOException e) { e.printStackTrace(); } }
From source file:algorithm.JPEGTextAddingTest.java
@Test public void jpegTextAddingTest() { try {//from www.j av a 2 s . co m File carrier = TestDataProvider.JPG_FILE; File payload1 = TestDataProvider.TXT_FILE; File payload2 = TestDataProvider.TXT_FILE_2; List<File> payloadList = new ArrayList<File>(); payloadList.add(payload1); payloadList.add(payload2); JPEGTextAdding algorithm = new JPEGTextAdding(); File outputFile = algorithm.encapsulate(carrier, payloadList); assertNotNull(outputFile); assertTrue(outputFile.length() > carrier.length()); // Test restore: Hashtable<String, RestoredFile> outputHash = new Hashtable<String, RestoredFile>(); for (RestoredFile file : algorithm.restore(outputFile)) { outputHash.put(file.getName(), file); } assertEquals(outputHash.size(), 3); RestoredFile restoredCarrier = outputHash.get(carrier.getName()); RestoredFile restoredPayload1 = outputHash.get(payload1.getName()); RestoredFile restoredPayload2 = outputHash.get(payload2.getName()); assertEquals(restoredCarrier.length(), carrier.length()); assertEquals(restoredPayload1.length(), payload1.length()); assertNotNull(restoredCarrier); assertNotNull(restoredPayload1); assertNotNull(restoredPayload2); assertEquals(FileUtils.checksumCRC32(carrier), FileUtils.checksumCRC32(restoredCarrier)); assertEquals(FileUtils.checksumCRC32(payload1), FileUtils.checksumCRC32(restoredPayload1)); assertEquals(FileUtils.checksumCRC32(payload2), FileUtils.checksumCRC32(restoredPayload2)); // check restoration metadata: assertEquals("" + carrier.getAbsolutePath(), restoredCarrier.originalFilePath); assertEquals("" + payload1.getAbsolutePath(), restoredPayload1.originalFilePath); assertEquals("" + payload2.getAbsolutePath(), restoredPayload2.originalFilePath); assertEquals(algorithm, restoredCarrier.algorithm); assertTrue(restoredCarrier.checksumValid); assertTrue(restoredPayload1.checksumValid); assertTrue(restoredPayload2.checksumValid); assertTrue(restoredCarrier.wasCarrier); assertFalse(restoredCarrier.wasPayload); assertTrue(restoredPayload1.wasPayload); assertFalse(restoredPayload1.wasCarrier); assertTrue(restoredPayload2.wasPayload); assertFalse(restoredPayload2.wasCarrier); assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload1)); assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload2)); assertFalse(restoredCarrier.relatedFiles.contains(restoredCarrier)); assertTrue(restoredPayload1.relatedFiles.contains(restoredCarrier)); assertTrue(restoredPayload1.relatedFiles.contains(restoredPayload2)); assertFalse(restoredPayload1.relatedFiles.contains(restoredPayload1)); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.sipfoundry.sipxconfig.admin.commserver.configdb.ConfigDbSettingAdaptor.java
public boolean set(String dbName, Collection settings) { Hashtable params = new Hashtable(); for (Iterator i = settings.iterator(); i.hasNext();) { Setting setting = (Setting) i.next(); setting.acceptVisitor(new ParamsCollector(params)); }/*from w w w.j av a2s . c o m*/ int set = m_configDbParameter.set(dbName, params); return set == params.size(); }
From source file:algorithm.TarPackagingTest.java
@Test public void singleTarPackagingTest() { try {// w w w .j a v a2 s . c om File carrier = TestDataProvider.TXT_FILE; File payload = TestDataProvider.XML_FILE; TarPackaging algorithm = new TarPackaging(); // Test encapsulation: List<File> carrierList = new ArrayList<File>(); carrierList.add(carrier); List<File> payloadList = new ArrayList<File>(); payloadList.add(payload); File outputFile = algorithm.encapsulate(carrier, payloadList); assertNotNull(outputFile); // Test restore: Hashtable<String, RestoredFile> outputHash = new Hashtable<String, RestoredFile>(); for (RestoredFile file : algorithm.restore(outputFile)) { outputHash.put(file.getName(), file); } assertEquals(2, outputHash.size()); RestoredFile restoredCarrier = outputHash.get(carrier.getName()); RestoredFile restoredPayload = outputHash.get(payload.getName()); assertNotNull(restoredCarrier); assertNotNull(restoredPayload); assertEquals(FileUtils.checksumCRC32(carrier), FileUtils.checksumCRC32(restoredCarrier)); assertEquals(FileUtils.checksumCRC32(payload), FileUtils.checksumCRC32(restoredPayload)); // check restoration metadata: // assertEquals("" + carrier.getAbsolutePath(), // restoredCarrier.originalFilePath); // assertEquals("" + payload.getAbsolutePath(), // restoredPayload.originalFilePath); assertEquals(algorithm, restoredCarrier.algorithm); assertTrue(restoredCarrier.checksumValid); assertTrue(restoredPayload.checksumValid); // Every file in a .tar archive is a payload file! assertTrue(restoredCarrier.wasPayload); assertFalse(restoredCarrier.wasCarrier); assertTrue(restoredPayload.wasPayload); assertFalse(restoredPayload.wasCarrier); assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload)); assertFalse(restoredCarrier.relatedFiles.contains(restoredCarrier)); assertTrue(restoredPayload.relatedFiles.contains(restoredCarrier)); assertFalse(restoredPayload.relatedFiles.contains(restoredPayload)); } catch (IOException e) { e.printStackTrace(); } }