List of usage examples for java.util Hashtable Hashtable
public Hashtable()
From source file:algorithm.PNGChunkAddingTest.java
@Test public void pngMultipleChunkAddingTest() { try {//w ww.j a va2s . com 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:com.acciente.induction.dispatcher.model.ModelPool.java
public ModelPool(Config.ModelDefs oModelDefs, ModelFactory oModelFactory) throws MethodNotFoundException, InvocationTargetException, ClassNotFoundException, ConstructorNotFoundException, ParameterProviderException, IllegalAccessException, InstantiationException { _oModelDefs = oModelDefs;// w w w .ja v a2s . co m _oModelFactory = oModelFactory; _oAppScopeModelMap = new Hashtable(); // we use a hashtable instead of a HashMap for safe concurrent access Log oLog = LogFactory.getLog(ModelPool.class); // initialize the models set to initialize on startup for (Iterator oIter = oModelDefs.getModelDefList().iterator(); oIter.hasNext();) { Config.ModelDefs.ModelDef oModelDef = (Config.ModelDefs.ModelDef) oIter.next(); if (oModelDef.isApplicationScope() && oModelDef.isInitOnStartUp()) { oLog.info("model-pool: initializing model: " + oModelDef.getModelClassName()); getApplicationScopeModel(oModelDef, null); } } }
From source file:algorithm.PDFFileAttacherTest.java
@Test public void pdfSingleFileAttacherTest() { try {// www.ja v a 2 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:it.unipmn.di.dcs.sharegrid.web.model.StandardEnvironment.java
private Context getContext() throws NamingException { if (this.envCtx == null) { Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, ManagementContextFactory.class.getName()); //env.put(Context.PROVIDER_URL, ""); //env.put(Context.OBJECT_FACTORIES, "foo.bar.ObjFactory"); //System.err.println( "INITIAL_CONTEXT_FACTORY: " + Context.INITIAL_CONTEXT_FACTORY );//XXX //System.err.println( "URL_PKG_PREFIXES: " + Context.URL_PKG_PREFIXES );//XXX env.put(Context.URL_PKG_PREFIXES, ManagementContextFactory.class.getName()); //System.err.println("ENV URI: " + envUri);//XXX Context ctx = new InitialContext(env); if (ctx != null) { //System.err.println("CONTEXT NOT NULL");//XXX String[] parts = this.envUri.split("/"); Context[] ctxs = new Context[parts.length + 1]; ctxs[0] = ctx;// ww w. jav a2s .c o m int i = 1; for (String envPart : parts) { //System.err.println("ENV PART: " + envPart);//XXX ctxs[i] = (Context) this.getOrCreateSubcontext(envPart, ctxs[i - 1]); i++; } this.envCtx = (Context) this.getOrCreateSubcontext(this.envUri, ctx); //System.err.println("ENV CONTEXT: " + this.envCtx);//XXX //Properties properties = new Properties(); //properties.put( "driverClassName", "com.mysql.jdbc.Driver" ); //properties.put( "url", "jdbc:mysql://localhost:3306/sharegrid" ); //properties.put( "username", "root" ); //properties.put( "password", "" ); //javax.sql.DataSource dataSource = org.apache.commons.dbcp.BasicDataSourceFactory.createDataSource( properties ); //this.envCtx.rebind( "jdbc/mysql", dataSource ); } } return this.envCtx; }
From source file:tl.lib.dataCollection.gui.MultipleChartsPanel.java
public MultipleChartsPanel(_CollectionGUIScenario scenario, String label, String description) { super(new GridBagLayout()); this.charts = new Hashtable<Integer, _ChartPanel>(); this.scenario = scenario; this.description = description; this.label = label; grid = new GridBagConstraints(); grid.weighty = 1;/*from w w w. ja v a 2 s .c om*/ grid.weightx = 1; grid.anchor = GridBagConstraints.PAGE_START; grid.fill = GridBagConstraints.BOTH; }
From source file:com.ibm.appscan.bamboo.plugin.impl.SASTScanTaskConfigurator.java
private Map<Long, String> getCredentials() { Map<Long, String> credentials = new Hashtable<Long, String>(); for (CredentialsData data : credentialsManager.getAllCredentials()) credentials.put(data.getId(), data.getName()); return credentials; }
From source file:algorithm.JPEGTextAddingTest.java
@Test public void jpegTextAddingTest() { try {// w w w .j av a 2 s . c o 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:algorithm.TarPackagingTest.java
@Test public void multipleTarPackagingTest() { 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); 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:edu.csun.ecs.cs.multitouchj.ui.event.ObjectEventManager.java
public ObjectEventManager() { activeObjects = new Hashtable<ObjectType, LinkedHashMap<Integer, ObjectObserverEvent>>(); for (ObjectType objectType : ObjectType.values()) { activeObjects.put(objectType, new LinkedHashMap<Integer, ObjectObserverEvent>()); }//from w w w . j a v a 2 s .c o m eventsCleaned = new Hashtable<ObjectType, Boolean>(); eventListenerManager = new EventListenerManager(); setRunning(false); setUpdated(false); }
From source file:com.lock.unlockInfo.servlet.SubmitUnlockImg.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpResponseModel responseModel = new HttpResponseModel(); try {/* ww w . ja v a2s .co m*/ boolean isMultipart = ServletFileUpload.isMultipartContent(request); // ??? if (isMultipart) { Hashtable<String, String> htSubmitParam = new Hashtable<String, String>(); // ?? List<String> fileList = new ArrayList<String>();// // DiskFileItemFactory?? // ????List // list??? FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List<FileItem> items = upload.parseRequest(request); Iterator<FileItem> iterator = items.iterator(); while (iterator.hasNext()) { FileItem item = iterator.next(); if (item.isFormField()) { // ? String sFieldName = item.getFieldName(); String sFieldValue = item.getString("UTF-8"); htSubmitParam.put(sFieldName, sFieldValue); } else { // ,??? String newFileName = System.currentTimeMillis() + "_" + UUID.randomUUID().toString() + ".jpg"; File filePath = new File( getServletConfig().getServletContext().getRealPath(Constants.File_Upload)); if (!filePath.exists()) { filePath.mkdirs(); } File file = new File(filePath, newFileName); if (!file.exists()) { file.createNewFile(); } //? BufferedInputStream bis = new BufferedInputStream(item.getInputStream()); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file)); byte[] b = new byte[1024]; int length = 0; while ((length = bis.read(b)) > 0) { bos.write(b, 0, length); } bos.close(); bis.close(); //?url String fileUrl = request.getRequestURL().toString(); fileUrl = fileUrl.substring(0, fileUrl.lastIndexOf("/")); //?URL fileUrl = fileUrl + Constants.File_Upload + "/" + newFileName; /**/ fileList.add(fileUrl); } } // String unlockInfoId = htSubmitParam.get("UnlockInfoId"); String imgType = htSubmitParam.get("ImgType"); String newFileUrl = fileList.get(0); UnlockInfoService unlockInfoService = (UnlockInfoService) context.getBean("unlockInfoService"); UnlockInfo unlockInfo = unlockInfoService.queryByPK(Long.valueOf(unlockInfoId)); if (imgType.equals("customerIdImg")) { unlockInfo.setCustomerIdImg(newFileUrl); } else if (imgType.equals("customerDrivingLicenseImg")) { unlockInfo.setCustomerDrivingLicenseImg(newFileUrl); } else if (imgType.equals("customerVehicleLicenseImg")) { unlockInfo.setCustomerVehicleLicenseImg(newFileUrl); } else if (imgType.equals("customerBusinessLicenseImg")) { unlockInfo.setCustomerBusinessLicenseImg(newFileUrl); } else if (imgType.equals("customerIntroductionLetterImg")) { unlockInfo.setCustomerIntroductionLetterImg(newFileUrl); } else if (imgType.equals("unlockWorkOrderImg")) { unlockInfo.setUnlockWorkOrderImg(newFileUrl); } /**/ unlockInfoService.update(unlockInfo); } } catch (Exception e) { e.printStackTrace(); responseModel.responseCode = "0"; responseModel.responseMessage = e.toString(); } /* ??? */ response.setHeader("content-type", "text/json;charset=utf-8"); response.getOutputStream().write(responseModel.toByteArray()); }