List of usage examples for java.util Hashtable size
public synchronized int size()
From source file:algorithm.PDFFileAttacherTest.java
@Test public void pdfSingleFileAttacherTest() { try {//from w ww . ja v a2 s . c om File carrier = TestDataProvider.PDF_FILE; File payload = TestDataProvider.TXT_FILE; PDFFileAttacher algorithm = new PDFFileAttacher(); // Test encapsulation: List<File> payloadList = new ArrayList<File>(); payloadList.add(payload); 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(2, outputHash.size()); RestoredFile restoredCarrier = outputHash.get(carrier.getName()); RestoredFile restoredPayload = outputHash.get(payload.getName()); assertNotNull(restoredCarrier); assertNotNull(restoredPayload); /* * TODO: as long as I can see, it is at the moment not possible to * remove the attached file with pdf box, so we can't restore the * carrier. We would have to use a different pdf library to solve * this. */ // assertEquals(FileUtils.checksumCRC32(carrier), // FileUtils.checksumCRC32(restoredCarrier)); assertEquals(FileUtils.checksumCRC32(payload), FileUtils.checksumCRC32(restoredPayload)); // check restoration metadata: // (This algorithm doesn't save original file paths, as it doesn't // use the payload segment) assertEquals(algorithm, restoredCarrier.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.PDFFileAttacherTest.java
@Test public void pdfMultipleFileAttacherTest() { try {// w w w . j a v a 2s . co m File carrier = TestDataProvider.PDF_FILE; File payload1 = TestDataProvider.TXT_FILE; File payload2 = TestDataProvider.TXT_FILE_2; List<File> payloadList = new ArrayList<File>(); payloadList.add(payload1); payloadList.add(payload2); PDFFileAttacher algorithm = new PDFFileAttacher(); // 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(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.TarPackagingTest.java
@Test public void multipleTarPackagingTest() { try {/*from w w w . j a va 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); TarPackaging algorithm = new TarPackaging(); // 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 and checksums, as it // doesn't use the payload segment and restoration metadata) assertEquals(algorithm, restoredCarrier.algorithm); assertTrue(restoredCarrier.checksumValid); assertTrue(restoredPayload1.checksumValid); assertTrue(restoredPayload2.checksumValid); // Every file in a .tar archive is a payload file! 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:com.globalsight.everest.webapp.pagehandler.administration.config.fileextension.FileExtensionMainHandler.java
private String checkDependencies(FileExtensionImpl fileExtension, HttpSession session) { ResourceBundle bundle = PageHandler.getBundle(session); FileExtensionDependencyChecker depChecker = new FileExtensionDependencyChecker(); Hashtable catDeps = depChecker.categorizeDependencies(fileExtension); StringBuffer deps = new StringBuffer(); if (catDeps.size() == 0) { return null; }// w w w . ja v a2s . com deps.append("<span class=\"errorMsg\">"); Object[] args = { bundle.getString("lb_file_extension") }; deps.append(MessageFormat.format(bundle.getString("msg_dependency"), args)); for (Enumeration e = catDeps.keys(); e.hasMoreElements();) { String key = (String) e.nextElement(); deps.append("<p>*** " + bundle.getString(key) + " ***<br>"); Vector values = (Vector) catDeps.get(key); for (int i = 0; i < values.size(); i++) { deps.append((String) values.get(i)); deps.append("<br>"); } } deps.append("</span>"); return deps.toString(); }
From source file:org.hdiv.filter.ResponseWrapper.java
/** * It updates cookies stored in the user's session with the wrapper's cookies. *//* ww w. j av a2 s .c o m*/ private void updateSessionCookies() { if (HDIVUtil.getHttpSession() != null) { Hashtable sessionOriginalCookies = (Hashtable) HDIVUtil.getHttpSession() .getAttribute(Constants.HDIV_COOKIES_KEY); if ((sessionOriginalCookies != null) && (sessionOriginalCookies.size() > 0)) { sessionOriginalCookies.putAll(this.cookies); HDIVUtil.getHttpSession().setAttribute(Constants.HDIV_COOKIES_KEY, sessionOriginalCookies); } else { HDIVUtil.getHttpSession().setAttribute(Constants.HDIV_COOKIES_KEY, this.cookies); } } }
From source file:com.mobilefirst.fiberlink.WebServiceRequest.java
/** * initializeRequestHeadersAndParameters iterates through Hashtable of attributes and sets against correct level in object * @param objectList: hashtable of parameters *//* w w w.ja v a2 s . c o m*/ @SuppressWarnings("unchecked") public void initializeRequestHeadersAndParameters(Hashtable<String, Object> objectList) { try { if (null != objectList) { if (0 != objectList.size()) { if (null != objectList.get("parameters")) { parameters.clear(); parameters = (Hashtable<String, String>) objectList.get("parameters"); } if (null != objectList.get("headers")) { headers.clear(); headers = (Hashtable<String, String>) objectList.get("headers"); } if (null != objectList.get("parts")) { parts = (Part[]) objectList.get("parts"); } } } } catch (Exception e) { } }
From source file:cgview.java
private CompressionStream getStream(Scene scene) { Hashtable objs = scene.getNamedObjects(); Shape3D shapes[] = new Shape3D[objs.size()]; objs.values().toArray(shapes);/*from w w w . j a va 2 s . c om*/ return new CompressionStream(positionQuant, colorQuant, normalQuant, shapes); }
From source file:ch.rgw.tools.StringTool.java
/** * Eine Hashtable in ein komprimiertes Byte-Array umwandeln * // ww w.j av a 2 s . co m * @param hash * die Hashtable * @param compressMode * GLZ, HUFF, BZIP2 * @param ExtInfo * Je nach Kompressmode ntige zusatzinfo * @return das byte-Array mit der komprimierten Hashtable * @deprecated compressmode is always ZIP now. */ @SuppressWarnings("unchecked") @Deprecated public static byte[] flatten(final Hashtable hash, final int compressMode, final Object ExtInfo) { ByteArrayOutputStream baos = null; OutputStream os = null; ObjectOutputStream oos = null; try { baos = new ByteArrayOutputStream(hash.size() * 30); switch (compressMode) { case GUESS: case ZIP: os = new ZipOutputStream(baos); ((ZipOutputStream) os).putNextEntry(new ZipEntry("hash")); break; case BZIP: os = new CBZip2OutputStream(baos); break; case HUFF: os = new HuffmanOutputStream(baos, (HuffmanTree) ExtInfo, 0); break; case GLZ: os = new GLZOutputStream(baos, hash.size() * 30); break; default: os = baos; } oos = new ObjectOutputStream(os); oos.writeObject(hash); if (os != null) { os.close(); } baos.close(); return baos.toByteArray(); } catch (Exception ex) { ExHandler.handle(ex); return null; } }
From source file:org.hdiv.filter.ValidatorHelperTest.java
public void testEditableParameterValidation() { MockHttpServletRequest request = (MockHttpServletRequest) HDIVUtil.getHttpServletRequest(); this.dataComposer.beginRequest(this.targetName); this.dataComposer.compose("paramName", "", true, "text"); String pageState = this.dataComposer.endRequest(); this.dataComposer.endPage(); request.addParameter(hdivParameter, pageState); request.addParameter("paramName", "<script>storeCookie()</script>"); RequestWrapper requestWrapper = new RequestWrapper(request); boolean result = helper.validate(requestWrapper).isValid(); assertTrue(result);/*from w w w . j ava2 s .co m*/ // Editable errors in request? Hashtable parameters = (Hashtable) requestWrapper.getAttribute(Constants.EDITABLE_PARAMETER_ERROR); assertEquals(1, parameters.size()); }
From source file:sim.app.sugarscape.util.ResultsGrapher.java
public int[] getUniqueIntVals(int[] vals) { int count = 0; int size = vals.length; Hashtable h = new Hashtable(size); for (int a = 0; a < size; a++) { h.put(new Integer(vals[a]), ""); }/*from w ww . j a va 2 s .com*/ int[] unique = new int[h.size()]; ArrayList dummy = new ArrayList(h.size()); java.util.Enumeration e = h.keys(); int counter = 0; while (e.hasMoreElements()) { unique[counter] = ((Integer) e.nextElement()).intValue(); System.out.print(unique[counter] + " "); dummy.add("."); counter++; } FastQSortAlgorithm f = new FastQSortAlgorithm(); f.sort(unique, dummy); return unique; }