Example usage for java.util Hashtable put

List of usage examples for java.util Hashtable put

Introduction

In this page you can find the example usage for java.util Hashtable put.

Prototype

public synchronized V put(K key, V value) 

Source Link

Document

Maps the specified key to the specified value in this hashtable.

Usage

From source file:algorithm.JPEGTextAddingTest.java

@Test
public void jpegTextAddingTest() {
    try {//from  w ww . j a v a2 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:org.picketlink.idm.performance.TestBase.java

public LdapContext getLdapContext() throws Exception {
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, LDAP_PROVIDER_URL);
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, LDAP_PRINCIPAL);
    env.put(Context.SECURITY_CREDENTIALS, LDAP_CREDENTIALS);

    return new InitialLdapContext(env, null);
}

From source file:gessi.ossecos.graph.GraphModel.java

public static void IStarJsonToGraphFile(String iStarModel, String layout, String typeGraph)
        throws ParseException {
    JSONParser parser = new JSONParser();
    JSONObject jsonObject = (JSONObject) parser.parse(iStarModel);

    JSONArray jsonArrayNodes = (JSONArray) jsonObject.get("nodes");
    JSONArray jsonArrayEdges = (JSONArray) jsonObject.get("edges");
    String modelType = jsonObject.get("modelType").toString();

    // System.out.println(modelType);
    // System.out.println(jsonArrayNodes.toJSONString());
    // System.out.println(jsonArrayEdges.toJSONString());

    System.out.println(jsonObject.toJSONString());

    Hashtable<String, String> nodesHash = new Hashtable<String, String>();
    Hashtable<String, String> boundaryHash = new Hashtable<String, String>();
    Hashtable<String, Integer> countNodes = new Hashtable<String, Integer>();
    ArrayList<String> boundaryItems = new ArrayList<String>();
    ArrayList<String> actorItems = new ArrayList<String>();
    GraphViz gv = new GraphViz();
    gv.addln(gv.start_graph());//  w w w  .  j  a  v  a  2 s. co m

    String nodeType;
    String nodeName;
    String nodeBoundary;
    for (int i = 0; i < jsonArrayNodes.size(); i++) {

        jsonObject = (JSONObject) jsonArrayNodes.get(i);
        nodeName = jsonObject.get("name").toString().replace(" ", "_");
        // .replace("(", "").replace(")", "");
        nodeName = nodeName.replaceAll("[\\W]|`[_]", "");
        nodeType = jsonObject.get("elemenType").toString();
        nodeBoundary = jsonObject.get("boundary").toString();
        // TODO: Verify type of diagram
        // if (!nodeType.equals("actor") & !nodeBoundary.equals("boundary"))
        // {
        if (countNodes.get(nodeName) == null) {
            countNodes.put(nodeName, 0);
        } else {
            countNodes.put(nodeName, countNodes.get(nodeName) + 1);
            nodeName += "_" + countNodes.put(nodeName, 0);

        }
        gv.addln(renderNode(nodeName, nodeType));

        // }

        nodesHash.put(jsonObject.get("id").toString(), nodeName);
        boundaryHash.put(jsonObject.get("id").toString(), nodeBoundary);
        if (nodeType.equals("actor")) {
            actorItems.add(nodeName);
        }
    }

    String edgeType = "";
    String source = "";
    String target = "";
    String edgeSubType = "";
    int subgraphCount = 0;
    boolean hasCluster = false;
    nodeBoundary = "na";
    String idSource;
    String idTarget;
    for (int i = 0; i < jsonArrayEdges.size(); i++) {

        jsonObject = (JSONObject) jsonArrayEdges.get(i);
        edgeSubType = jsonObject.get("linksubtype").toString();
        edgeType = renderEdge(edgeSubType, jsonObject.get("linktype").toString());
        idSource = jsonObject.get("source").toString();
        idTarget = jsonObject.get("target").toString();
        source = nodesHash.get(idSource);
        target = nodesHash.get(idTarget);

        if (!boundaryHash.get(idSource).toString().equals("boundary")
                && !boundaryHash.get(idTarget).toString().equals("boundary")) {
            if (!boundaryHash.get(idSource).toString().equals(nodeBoundary)) {
                nodeBoundary = boundaryHash.get(idSource).toString();
                if (hasCluster) {
                    gv.addln(gv.end_subgraph());
                    hasCluster = false;

                } else {
                    hasCluster = true;
                }
                gv.addln(gv.start_subgraph(subgraphCount));
                gv.addln(actorItems.get(subgraphCount++));
                gv.addln("style=filled;");
                gv.addln("color=lightgrey;");

            }
            gv.addln(source + "->" + target + edgeType);

        } else {

            boundaryItems.add(source + "->" + target + edgeType);

        }

    }
    if (subgraphCount > 0) {
        gv.addln(gv.end_subgraph());
    }
    for (String boundaryE : boundaryItems) {
        gv.addln(boundaryE);
    }
    gv.addln(gv.end_graph());

    String type = typeGraph;
    // String type = "dot";
    // String type = "fig"; // open with xfig
    // String type = "pdf";
    // String type = "ps";
    // String type = "svg"; // open with inkscape
    // String type = "png";
    // String type = "plain";

    String repesentationType = layout;
    // String repesentationType= "neato";
    // String repesentationType= "fdp";
    // String repesentationType= "sfdp";
    // String repesentationType= "twopi";
    // String repesentationType= "circo";

    // //File out = new File("/tmp/out"+gv.getImageDpi()+"."+ type); //
    // Linux
    File out = new File("Examples/out." + type); // Windows
    gv.writeGraphToFile(gv.getGraph(gv.getDotSource(), type, repesentationType), out);

}

From source file:com.softlayer.objectstorage.Container.java

/**
 * enable CDN access to the files in this container
 * /* www. j  a  v a 2 s  .  c o m*/
 * @param ttl
 *            the ttl for the CDN objects in this container
 * @throws EncoderException
 * @throws IOException
 */
public void enableCDN(Integer ttl) throws EncoderException, IOException {
    Hashtable<String, String> params = super.createAuthParams();
    if (ttl != null)
        params.put(Client.X_CDN_TTL, Integer.toString(ttl));
    String uName = super.saferUrlEncode(this.name);
    super.put(params, null, super.cdnurl + "/" + uName);
}

From source file:com.softlayer.objectstorage.ObjectFile.java

/**
 * make a file copy in this container from another file
 * /*from   w w  w  .  j a  v a2s.c o  m*/
 * @param container
 *            the source container to copy from
 * @param objectName
 *            the source file to copy from
 * @throws EncoderException
 * @throws IOException
 */
public void copyFrom(String container, String objectName) throws EncoderException, IOException {
    String cuName = super.saferUrlEncode(container);
    String cfName = super.saferUrlEncode(objectName);
    String sourceUrl = cuName + "/" + cfName;
    Hashtable<String, String> params = super.createAuthParams();
    params.put(Client.X_COPY_FROM, sourceUrl);

    String uName = super.saferUrlEncode(this.containerName);
    String fName = super.saferUrlEncode(this.name);

    super.put(params, null, super.storageurl + "/" + uName + "/" + fName);
}

From source file:br.com.uol.runas.classloader.ClassLoaderGC.java

private void deregisterOracleDiagnosabilityMBean(WeakReference<ClassLoader> classLoader) {
    try {//from  w w  w. j a  v a  2  s.co  m
        final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        final Hashtable<String, String> keys = new Hashtable<String, String>();
        keys.put("type", "diagnosability");
        keys.put("name", classLoader.get().getClass().getName() + "@"
                + Integer.toHexString(classLoader.get().hashCode()).toLowerCase());
        mbs.unregisterMBean(new ObjectName("com.oracle.jdbc", keys));
    } catch (Throwable e) {
        e.printStackTrace();
    }
}

From source file:com.paxxis.cornerstone.messaging.service.shell.ServiceShell.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private void doUnbind(String[] vals) throws NamingException {
    String url = "rmi://localhost:" + vals[1];
    String serviceName = vals[0];
    System.out.println("Unbinding " + url + "/" + serviceName);
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory");
    env.put(Context.PROVIDER_URL, url);

    Context ictx = new InitialContext(env);
    try {//  w w  w . jav  a  2  s.c  o  m
        ictx.unbind(serviceName);
        System.out.println("Done");
    } catch (Exception ex) {
        System.err.println(ex.getMessage() + ex.getCause().getMessage());
    }
}

From source file:EmailTree.java

public void init() {
    Hashtable h = new Hashtable();
    Hashtable paul = new Hashtable();
    paul.put("Work", addresses[0]);
    paul.put("Home", addresses[1]);
    Hashtable damian = new Hashtable();
    damian.put("Work", addresses[2]);
    damian.put("Pager", addresses[3]);
    damian.put("Home", addresses[4]);
    Hashtable angela = new Hashtable();
    angela.put("Home", addresses[5]);
    h.put("Paul", paul);
    h.put("Damian", damian);
    h.put("Angela", angela);
    tree = new JTree(h);

    DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer();
    renderer.setOpenIcon(new ImageIcon("mailboxdown.gif"));
    renderer.setClosedIcon(new ImageIcon("mailboxup.gif"));
    renderer.setLeafIcon(new ImageIcon("letter.gif"));
    EmailTreeCellEditor emailEditor = new EmailTreeCellEditor();
    DefaultTreeCellEditor editor = new DefaultTreeCellEditor(tree, renderer, emailEditor);
    tree.setCellEditor(editor);/*from   ww  w  .  ja va 2 s .com*/
    tree.setEditable(true);

    getContentPane().add(tree, BorderLayout.CENTER);
}

From source file:com.adobe.acs.commons.util.ResourceServiceManager.java

@SuppressWarnings("squid:S1149")
private ServiceRegistration registerService(String id, Resource config) {
    Hashtable<String, Object> props = new Hashtable<String, Object>();
    props.put(SERVICE_OWNER_KEY, getClass().getCanonicalName());
    props.put(CONFIGURATION_ID_KEY, id);
    ServiceRegistration serviceRegistration = registerServiceObject(config, props);

    registeredServices.put(id, serviceRegistration);
    log.debug("Automatic Package Replication job {} successfully updated with service {}", id,
            serviceRegistration.getReference().getProperty(Constants.SERVICE_ID));

    return serviceRegistration;
}

From source file:com.nokia.helium.jpa.ORMEntityManager.java

/**  
 * Constructor.//w ww  .j  ava2 s .c om
 * @param urlPath path for which entity manager to be
 * created.
 */
@SuppressWarnings("unchecked")
public ORMEntityManager(String urlPath) throws Exception {
    String name = "metadata";
    Hashtable persistProperties = new Hashtable();
    persistProperties.put("javax.persistence.jdbc.driver", "org.apache.derby.jdbc.EmbeddedDriver");
    persistProperties.put("javax.persistence.jdbc.url", "jdbc:derby:" + urlPath);
    persistProperties.put(PersistenceUnitProperties.PERSISTENCE_CONTEXT_CLOSE_ON_COMMIT, "false");
    persistProperties.put(PersistenceUnitProperties.PERSISTENCE_CONTEXT_REFERENCE_MODE, "WEAK");
    persistProperties.put(PersistenceUnitProperties.BATCH_WRITING, "JDBC");
    persistProperties.put("eclipselink.read-only", "true");
    persistProperties.put(PersistenceUnitProperties.LOGGING_LEVEL, "warning");
    File dbFile = new File(urlPath);
    commitCountObject = new ORMCommitCount();
    if (dbFile.exists()) {
        try {
            log.debug("checking db integrity for :" + urlPath);
            if (!checkDatabaseIntegrity(urlPath)) {
                log.debug("db integrity failed cleaning up old db");
                try {
                    log.debug("deleting the url path" + urlPath);
                    FileUtils.forceDelete(dbFile);
                    log.debug("successfully removed the urlpath" + urlPath);
                } catch (java.io.IOException iex) {
                    log.debug("deleting the db directory failed", iex);
                    throw new BuildException("failed deleting corrupted db", iex);
                }
            } else {
                log.debug("db exists and trying to create entity manager");
                EntityManagerFactory factory = Persistence.createEntityManagerFactory(name, persistProperties);
                entityManager = factory.createEntityManager();
                entityManager.getTransaction().begin();
                return;
            }
        } catch (Exception ex) {
            log.debug("Failed to open the database, might be corrupted, creating new db", ex);
            try {
                FileUtils.deleteDirectory(dbFile);
            } catch (java.io.IOException iex) {
                log.debug("deleting the db directory failed");
                throw iex;
            }
        }
    }
    log.debug("url path not exists" + urlPath + "creating it");
    persistProperties.put("javax.persistence.jdbc.url", "jdbc:derby:" + urlPath + ";create=true");
    persistProperties.put(PersistenceUnitProperties.DDL_GENERATION, "create-tables");
    persistProperties.put(PersistenceUnitProperties.DDL_GENERATION_MODE, "database");
    persistProperties.put(PersistenceUnitProperties.PERSISTENCE_CONTEXT_CLOSE_ON_COMMIT, "false");
    persistProperties.put(PersistenceUnitProperties.PERSISTENCE_CONTEXT_REFERENCE_MODE, "WEAK");
    persistProperties.put(PersistenceUnitProperties.BATCH_WRITING, "JDBC");
    persistProperties.put("eclipselink.read-only", "true");
    EntityManagerFactory factory = Persistence.createEntityManagerFactory(name, persistProperties);
    entityManager = factory.createEntityManager();
    entityManager.getTransaction().begin();
    entityManager.persist(new Version());
    entityManager.getTransaction().commit();
    entityManager.clear();
    entityManager.getTransaction().begin();
}