Example usage for java.lang String intern

List of usage examples for java.lang String intern

Introduction

In this page you can find the example usage for java.lang String intern.

Prototype

public native String intern();

Source Link

Document

Returns a canonical representation for the string object.

Usage

From source file:com.recalot.model.data.connections.reddit.RedditDataSource.java

private void readFile(String userName, File file) {

    try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)))) {
        String line = null;/*from  w w  w  .ja v  a2  s  . co m*/

        while ((line = reader.readLine()) != null) {
            int i = 0;
            String[] split = line.split("00;");

            if (split.length == 2) {

                Date date = DatatypeConverter.parseDateTime(split[0] + "00").getTime();

                List<String> words = splitIntoWords(split[1]);

                for (String word : words) {
                    addNewItem(word.intern());
                    addWordInteraction(userName.intern(), word.intern(), (interactionId++) + "", date, i++);
                }
            }
        }
    } catch (IOException x) {
        x.printStackTrace();
    }
}

From source file:Profiler.java

/**
 * Notifies the profiler that a routine has started
 * // w  w  w.  ja  v a 2s . c  o  m
 * @param name
 *            The name of the routine
 */
public void startRoutine(String name) {
    name = name.intern();
    int i;
    for (i = 1; i < theRoutines.length && name != theRoutines[i]; i++)
        ;
    if (i == theRoutines.length) {
        String[] newRoutines = new String[i + 1];
        System.arraycopy(theRoutines, 0, newRoutines, 0, i);
        newRoutines[i] = name;
        theRoutines = newRoutines;
        long[] longArray = new long[i + 1];
        System.arraycopy(theRoutineStartTimes, 0, longArray, 0, i);
        longArray[i] = -1;
        theRoutineStartTimes = longArray;
        longArray = new long[i + 1];
        System.arraycopy(theRoutineProfiles, 0, longArray, 0, i);
        longArray[i] = 0;
        theRoutineProfiles = longArray;
        int[] intArray = new int[i + 1];
        System.arraycopy(theCallCounts, 0, intArray, 0, i);
        intArray[i] = 0;
        theCallCounts = intArray;
    }
    if (theRoutineStartTimes[i] >= 0) {
        stopRoutine(name);
        // throw new IllegalStateException("Routine " + name
        // + " already running: recursion not supported");
    }
    long time = System.currentTimeMillis();
    theRoutineStartTimes[i] = time;
    theCallCounts[i]++;
    if (theRoutineStartTimes[0] >= 0) { // Stop the "other" routine
        theRoutineProfiles[0] += time - theRoutineStartTimes[0];
        theRoutineStartTimes[0] = -1;
    }
}

From source file:org.dataconservancy.dcs.ingest.services.util.ElmSipStager.java

public Dcp getSIP(String key) {
    synchronized (key.intern()) {

        InputStream stream = null;
        try {//w w  w  .j  av  a 2  s. com
            stream = entityStore.get(key);
        } catch (EntityNotFoundException e) {
            return null;
        }

        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        final TeeInputStream tee = new TeeInputStream(stream, out);
        try {
            return modelBuilder.buildSip(tee);
        } catch (InvalidXmlException e) {
            try {
                log.error("Invalid XML in the SIP with key [{}]: {}\n{}\n", new Object[] { key, e.getMessage(),
                        IOUtils.toString(new ByteArrayInputStream(out.toByteArray())) });
            } catch (IOException ioe) {

            }
            throw new RuntimeException(e);
        } catch (RuntimeException e) {
            try {
                log.error("Error reading SIP with key [{}]: {}\n{}\n", new Object[] { key, e.getMessage(),
                        IOUtils.toString(new ByteArrayInputStream(out.toByteArray())) });
            } catch (IOException ioe) {

            }
            throw new RuntimeException(e);
        } finally {
            try {
                out.close();
                tee.close();
                stream.close();
            } catch (IOException e) {

            }
        }
    }
}

From source file:org.dataconservancy.dcs.ingest.util.SeadElmSipStager.java

public ResearchObject getSIP(String key) {
    synchronized (key.intern()) {

        InputStream stream = null;
        try {/*from w w w  .j a  v  a2 s. c  om*/
            stream = entityStore.get(key);
        } catch (EntityNotFoundException e) {
            return null;
        }

        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        final TeeInputStream tee = new TeeInputStream(stream, out);
        try {
            return (ResearchObject) modelBuilder.buildSip(tee);
        } catch (InvalidXmlException e) {
            try {
                log.error("Invalid XML in the SIP with key [{}]: {}\n{}\n", new Object[] { key, e.getMessage(),
                        IOUtils.toString(new ByteArrayInputStream(out.toByteArray())) });
            } catch (IOException ioe) {

            }
            throw new RuntimeException(e);
        } catch (RuntimeException e) {
            try {
                log.error("Error reading SIP with key [{}]: {}\n{}\n", new Object[] { key, e.getMessage(),
                        IOUtils.toString(new ByteArrayInputStream(out.toByteArray())) });
            } catch (IOException ioe) {

            }
            throw new RuntimeException(e);
        } finally {
            try {
                out.close();
                tee.close();
                stream.close();
            } catch (IOException e) {

            }
        }
    }
}

From source file:com.opensearchserver.client.common.search.query.SearchFieldQuery.java

/**
 * @param field//  w  w  w.j  a  va  2  s.c om
 *            the name of the field
 * @param value
 *            the query value for this field
 * @return this instance
 */
@JsonIgnore
@XmlTransient
public SearchFieldQuery setQueryStringMap(String field, String value) {
    if (queryStringMap == null)
        queryStringMap = new LinkedHashMap<String, String>();
    queryStringMap.put(field.intern(), value);
    return this;
}

From source file:ru.runa.wfe.lang.GraphElement.java

public void setDescription(String description) {
    this.description = null == description ? null : description.intern();
}

From source file:com.quinsoft.zeidon.domains.DynamicTableDomain.java

protected View loadApplicationDomainView(Task task, DomainContext context, String viewName) {
    Application app = getApplication();/*from   w w  w .  jav  a2 s .co  m*/
    synchronized (viewName.intern()) {
        View domainView = app.getViewByName(viewName);
        if (domainView != null)
            return domainView;

        domainView = activateApplicationDomain(task, context);
        app.setNameForView(viewName, domainView);
        return domainView;
    }
}

From source file:org.wso2.carbon.core.multitenancy.utils.TenantAxisUtils.java

public static ConfigurationContext getTenantConfigurationContext(String tenantDomain,
        ConfigurationContext mainConfigCtx) {
    ConfigurationContext tenantConfigCtx;

    Boolean isTenantActive;//  w  w  w. j av a2 s .c om
    try {
        isTenantActive = CarbonCoreDataHolder.getInstance().getRealmService().getTenantManager()
                .isTenantActive(getTenantId(tenantDomain));
    } catch (Exception e) {
        throw new RuntimeException("Error while getting tenant activation status.", e);
    }

    if (!isTenantActive) {
        throw new RuntimeException("Trying to access inactive tenant domain : " + tenantDomain);
    }

    if (tenantReadWriteLocks.get(tenantDomain) == null) {
        synchronized (tenantDomain.intern()) {
            if (tenantReadWriteLocks.get(tenantDomain) == null) {
                tenantReadWriteLocks.put(tenantDomain, new ReentrantReadWriteLock());
            }
        }
    }
    Lock tenantReadLock = tenantReadWriteLocks.get(tenantDomain).readLock();
    try {
        tenantReadLock.lock();
        Map<String, ConfigurationContext> tenantConfigContexts = getTenantConfigurationContexts(mainConfigCtx);
        tenantConfigCtx = tenantConfigContexts.get(tenantDomain);
        if (tenantConfigCtx == null) {
            try {
                tenantConfigCtx = createTenantConfigurationContext(mainConfigCtx, tenantDomain);
            } catch (Exception e) {
                throw new RuntimeException(
                        "Cannot create tenant ConfigurationContext for tenant " + tenantDomain, e);
            }
        }
        tenantConfigCtx.setProperty(MultitenantConstants.LAST_ACCESSED, System.currentTimeMillis());
    } finally {
        tenantReadLock.unlock();
    }
    return tenantConfigCtx;
}

From source file:org.diorite.chat.placeholder.ArgPlaceholderData.java

ArgPlaceholderData(final String fullName, final String objectName, final PlaceholderItem<T> item,
        final Object[] args) {
    this.fullName = fullName.intern();
    this.objectName = objectName.intern();
    this.item = item;
    this.args = args;
    for (final Object arg : args) {
        if (arg instanceof Supplier) {
            this.containsSubPlaceholders = true;
            return;
        }//  w  w w  .  j a  v  a  2 s  .co  m
    }
    this.containsSubPlaceholders = false;
}

From source file:org.jivesoftware.openfire.vcard.DefaultVCardProvider.java

public Element loadVCard(String username) {

    synchronized (username.intern()) {
        if (db == null) {
            db = MongoDbConnectionManager.reconnect();
        }//from  w  w w.  j a  v  a 2s  . co  m
        if (db == null)
            return null;

        Element vCardElement = null;

        SAXReader xmlReader = null;
        try {

            DBCollection coll = db.getCollection("gUser");
            BasicDBObject doc = new BasicDBObject("photoId", 1).append("vcard", 1);

            BasicDBObject q = new BasicDBObject("himId", username);
            DBObject res = coll.findOne(q, doc);

            if (res != null) {
                BasicDBObject photo = (BasicDBObject) res.get("photoId");
                BasicDBObject vcardXml = (BasicDBObject) res.get("vcard");
                if (vcardXml != null) {
                    vCardElement = new DOMElement("vCard", new Namespace(null, "vcard-temp-ext"));
                    String url = (String) vcardXml.getString("url");
                    Element urlE = new DOMElement("url");
                    Element type = new DOMElement("type");
                    type.setText((String) vcardXml.getString("type"));
                    urlE.setText(url);
                    vCardElement.add(urlE);
                } else if (photo != null) {
                    Element photoEl = new DOMElement("PHOTO");
                    Element bin = new DOMElement("BINVAL");
                    Element type = new DOMElement("type");
                    vCardElement = new DOMElement("vCard", new Namespace(null, "vcard-temp"));
                    String url = (String) photo.getString("url");
                    type.setText(photo.getString("contentType"));
                    HttpClient client = new HttpClient();
                    GetMethod method = new GetMethod(url);
                    client.executeMethod(method);
                    if (method.getStatusCode() == HttpStatus.SC_OK) {
                        InputStream ios = method.getResponseBodyAsStream();
                        byte[] data = new byte[2048];
                        int len = 0;
                        StringBuilder builder = new StringBuilder();
                        while ((len = ios.read(data)) != -1) {
                            builder.append(Base64.encodeBytes(data, 0, len, Base64.NO_OPTIONS));
                        }
                        bin.setText(builder.toString());
                        ios.close();
                    }
                    photoEl.add(type);
                    photoEl.add(bin);
                    vCardElement.add(photoEl);
                }

            }

        } catch (Exception e) {
            Log.error("Error loading vCard of username: " + username, e);
        } finally {

        }
        return vCardElement;
    }
}