List of usage examples for java.lang String intern
public native String intern();
From source file:org.apache.axiom.om.impl.SwitchingWrapper.java
/** * @return Returns String.//w w w .ja v a2 s. c o m * @see javax.xml.stream.XMLStreamReader#getNamespaceURI() */ public String getNamespaceURI() { String returnStr; if (parser != null && currentEvent != END_DOCUMENT) { returnStr = parser.getNamespaceURI(); } else { if ((currentEvent == START_ELEMENT) || (currentEvent == END_ELEMENT) || (currentEvent == NAMESPACE)) { OMNamespace ns = ((OMElement) lastNode).getNamespace(); if (ns == null) { returnStr = null; } else { String namespaceURI = ns.getNamespaceURI(); returnStr = namespaceURI.length() == 0 ? null : namespaceURI; } } else { throw new IllegalStateException(); } } // By default most parsers don't intern the namespace. // Unfortunately the property to detect interning on the delegate parsers is hard to detect. // Woodstox has a proprietary property on the XMLInputFactory. // IBM has a proprietary property on the XMLStreamReader. // For now only force the interning if requested. if (this.isNamespaceURIInterning()) { returnStr = (returnStr != null) ? returnStr.intern() : null; } return returnStr; }
From source file:ubic.basecode.bio.geneset.GeneAnnotations.java
/** * @param bis/*from w w w .j av a2 s. c o m*/ * @param activeGenes * @throws IOException */ protected void read(InputStream bis, Set<String> activeGenes) throws IOException { log.debug("Entering GeneAnnotations.read"); if (bis == null) { throw new IOException("Inputstream was null"); } if (bis.available() == 0) { throw new IOException("No bytes to read from the annotation file."); } BufferedReader dis = new BufferedReader(new InputStreamReader(bis)); Collection<String> probeIds = new ArrayList<String>(); String classIds = null; // loop through rows. Makes hash map of probes to go, and map of go to // probes. int n = 0; String line = ""; tick(); while ((line = dis.readLine()) != null) { if (line.startsWith("#")) continue; // String[] tokens = StringUtils.splitPreserveAllTokens( line, "\t" ); String[] tokens = line.split("\t"); int length = tokens.length; if (length < 2) continue; String probe = tokens[0].intern(); String gene = tokens[1].intern(); if (filterNonSpecific && (gene.contains("|") || gene.contains(","))) { continue; } if (activeGenes != null && !activeGenes.contains(probe)) { continue; } // if ( log.isDebugEnabled() ) log.debug( "probe: " + probe ); storeProbeAndGene(probeIds, probe, gene); /* read gene description */ if (length >= 3) { String description = tokens[2].intern(); if (description.length() > 0) { probeToDescription.put(probe.intern(), description.intern()); } else { probeToDescription.put(probe.intern(), NO_DESCRIPTION); } } else { probeToDescription.put(probe.intern(), NO_DESCRIPTION); continue; } /* read GO data */ if (length >= 4) { classIds = tokens[3]; extractPipeDelimitedGoIds(classIds, probe); } if (messenger != null && n % 500 == 0) { messenger.showStatus("Read " + n + " probes"); try { Thread.sleep(2); } catch (InterruptedException e) { dis.close(); throw new CancellationException(); } } n++; } /* Fill in the genegroupreader and the classmap */ dis.close(); resetSelectedProbes(); if (probeToGeneName.size() == 0 || geneSetToProbeMap.size() == 0) { throw new IllegalArgumentException( "The gene annotations had invalid information. Please check the format."); } }
From source file:com.cloud.storage.resource.VmwareStorageProcessor.java
private Ternary<String, Long, Long> createTemplateFromVolume(VirtualMachineMO vmMo, String installPath, long templateId, String templateUniqueName, String secStorageUrl, String volumePath, String workerVmName, Integer nfsVersion) throws Exception { String secondaryMountPoint = mountService.getMountPoint(secStorageUrl, nfsVersion); String installFullPath = secondaryMountPoint + "/" + installPath; synchronized (installPath.intern()) { Script command = new Script(false, "mkdir", _timeout, s_logger); command.add("-p"); command.add(installFullPath);/* w ww . j a v a 2 s . c o m*/ String result = command.execute(); if (result != null) { String msg = "unable to prepare template directory: " + installPath + ", storage: " + secStorageUrl + ", error msg: " + result; s_logger.error(msg); throw new Exception(msg); } } VirtualMachineMO clonedVm = null; try { Pair<VirtualDisk, String> volumeDeviceInfo = vmMo.getDiskDevice(volumePath); if (volumeDeviceInfo == null) { String msg = "Unable to find related disk device for volume. volume path: " + volumePath; s_logger.error(msg); throw new Exception(msg); } if (!vmMo.createSnapshot(templateUniqueName, "Temporary snapshot for template creation", false, false)) { String msg = "Unable to take snapshot for creating template from volume. volume path: " + volumePath; s_logger.error(msg); throw new Exception(msg); } // 4 MB is the minimum requirement for VM memory in VMware Pair<VirtualMachineMO, String[]> cloneResult = vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first())); clonedVm = cloneResult.first(); clonedVm.exportVm(secondaryMountPoint + "/" + installPath, templateUniqueName, false, false); // Get VMDK filename String templateVMDKName = ""; File[] files = new File(installFullPath).listFiles(); if (files != null) { for (File file : files) { String fileName = file.getName(); if (fileName.toLowerCase().startsWith(templateUniqueName) && fileName.toLowerCase().endsWith(".vmdk")) { templateVMDKName += fileName; break; } } } long physicalSize = new File(installFullPath + "/" + templateVMDKName).length(); OVAProcessor processor = new OVAProcessor(); Map<String, Object> params = new HashMap<String, Object>(); params.put(StorageLayer.InstanceConfigKey, _storage); processor.configure("OVA Processor", params); long virtualSize = processor.getTemplateVirtualSize(installFullPath, templateUniqueName); postCreatePrivateTemplate(installFullPath, templateId, templateUniqueName, physicalSize, virtualSize); writeMetaOvaForTemplate(installFullPath, templateUniqueName + ".ovf", templateVMDKName, templateUniqueName, physicalSize); return new Ternary<String, Long, Long>(installPath + "/" + templateUniqueName + ".ova", physicalSize, virtualSize); } finally { if (clonedVm != null) { clonedVm.detachAllDisks(); clonedVm.destroy(); } vmMo.removeSnapshot(templateUniqueName, false); } }
From source file:flex2.compiler.mxml.ImplementationGenerator.java
private QualifiedIdentifierNode generateMxInternalQualifiedIdentifier(String name, boolean intern) { if (intern) { name = name.intern(); }//from w ww.j a v a 2s . co m return nodeFactory.qualifiedIdentifier(generateMxInternalAttributeList(), name); }
From source file:de.interactive_instruments.ShapeChange.Options.java
/** * Depending upon whether or not string interning shall be used during * processing, this method interns the given string array or an * internized copy.// w w w . ja va 2 s . c o m * * @param array * @return */ public String[] internalize(String[] array) { if (useStringInterning) { String[] result = new String[array.length]; int i = 0; for (String s : array) result[i++] = s.intern(); return result; } else { return array; } }
From source file:org.sakaiproject.authz.impl.DbAuthzGroupService.java
/** * Check / assure this function name is defined. * * @param name//from w w w. j a v a2s . c o m * the role name. */ protected void checkFunctionName(String name) { if (name == null) return; name = name.intern(); // check the cache to see if the function name already exists if (m_functionCache.contains(name)) return; // see if we have this on the db String statement = dbAuthzGroupSql.getCountRealmFunctionSql(); Object[] fields = new Object[1]; fields[0] = name; List results = sqlService().dbRead(statement, fields, new SqlReader() { public Object readSqlResultRecord(ResultSet result) { try { int count = result.getInt(1); return Integer.valueOf(count); } catch (SQLException ignore) { return null; } } }); boolean rv = false; if (!results.isEmpty()) { rv = ((Integer) results.get(0)).intValue() > 0; } // write if we didn't find it if (!rv) { statement = dbAuthzGroupSql.getInsertRealmFunctionSql(); // write, but if it fails, we don't really care - it will fail if another app server has just written this function sqlService().dbWriteFailQuiet(null, statement, fields); } // cache the existance of the function name synchronized (m_functionCache) { m_functionCache.add(name); } }
From source file:org.sakaiproject.authz.impl.DbAuthzGroupService.java
/** * Check / assure this role name is defined. * * @param name//from www . j a v a 2s . c o m * the role name. */ protected void checkRoleName(String name) { if (name == null) return; name = name.intern(); // check the cache to see if the role name already exists if (getRealmRoleKey(name) != null) return; // see if we have it in the db String statement = dbAuthzGroupSql.getCountRealmRoleSql(); Object[] fields = new Object[1]; fields[0] = name; List results = sqlService().dbRead(statement, fields, new SqlReader() { public Object readSqlResultRecord(ResultSet result) { try { int count = result.getInt(1); return Integer.valueOf(count); } catch (SQLException ignore) { return null; } } }); boolean rv = false; if (!results.isEmpty()) { rv = ((Integer) results.get(0)).intValue() > 0; } // write if we didn't find it if (!rv) { statement = dbAuthzGroupSql.getInsertRealmRoleSql(); // write, but if it fails, we don't really care - it will fail if another app server has just written this role name sqlService().dbWriteFailQuiet(null, statement, fields); } synchronized (m_roleNameCache) { //Get realm role Key statement = dbAuthzGroupSql.getSelectRealmRoleKeySql(); results = sqlService().dbRead(statement, fields, new SqlReader() { public Object readSqlResultRecord(ResultSet result) { try { String name = result.getString(1); Integer key = result.getInt(2); RealmRole realmRole = new RealmRole(name, key); m_roleNameCache.add(realmRole); } catch (SQLException ignore) { } return null; } }); } }
From source file:de.interactive_instruments.ShapeChange.Options.java
/** * Depending upon whether or not string interning shall be used during * processing, this method interns the given string. * * @param string/*from w w w.j a v a 2 s.c o m*/ * @return */ public String internalize(String string) { if (string == null) { return null; } else if (useStringInterning) { return string.intern(); } else { return string; } }
From source file:ubic.basecode.bio.geneset.GeneAnnotations.java
/** * @param bis/*from w w w . ja v a 2 s . c om*/ * @param object */ protected void readAffyCsv(InputStream bis, Set<String> activeGenes) throws IOException { if (bis == null) { throw new IOException("Inputstream was null"); } BufferedReader dis = new BufferedReader(new InputStreamReader(bis)); Collection<String> probeIds = new ArrayList<String>(); String classIds = null; String header = dis.readLine(); if (header == null) { throw new IOException("File had no header"); } int numFields = getAffyNumFields(header); int probeIndex = getAffyProbeIndex(header); int goBpIndex = getAffyBpIndex(header); int goCcIndex = getAffyCcIndex(header); int goMfIndex = getAffyMfIndex(header); int geneNameIndex = getAffyGeneNameIndex(header); int geneSymbolIndex = getAffyGeneSymbolIndex(header); int alternateGeneSymbolIndex = getAffyAlternateGeneSymbolIndex(header); if (probeIndex < 0) { throw new IllegalStateException("Invalid AFFY file format: could not find the probe set id column"); } if (geneNameIndex < 0) { throw new IllegalStateException("Invalid AFFY file format: could not find the gene name column"); } if (geneSymbolIndex < 0) { throw new IllegalStateException("Invalid AFFY file format: could not find the gene symbol column"); } if (goBpIndex < 0) { throw new IllegalStateException("Invalid AFFY file format: No biological process data were found"); } else if (goCcIndex < 0) { throw new IllegalStateException("Invalid AFFY file format: No cellular component data were found"); } else if (goMfIndex < 0) { throw new IllegalStateException("Invalid AFFY file format: No molecular function data were found"); } log.debug("Read header"); tick(); assert (numFields > probeIndex + 1 && numFields > geneSymbolIndex + 1); Pattern pat = Pattern.compile("[0-9]+"); // loop through rows. Makes hash map of probes to go, and map of go to // probes. int n = 0; String line = ""; log.debug("File opened okay, parsing Affy CSV"); while ((line = dis.readLine()) != null) { if (Thread.currentThread().isInterrupted()) { dis.close(); throw new CancellationException(); } String[] fields = StringUtil.csvSplit(line); if (fields.length < probeIndex + 1 || fields.length < geneSymbolIndex + 1) { continue; // skip lines that don't meet criteria. } String probe = fields[probeIndex]; String gene = fields[geneSymbolIndex]; if (StringUtils.isBlank(probe) || probe.equals("---")) { throw new IllegalStateException("Probe name was missing or invalid at line " + n + "; it is possible the file format is not readable; contact the developers."); } if (StringUtils.isBlank(gene) || gene.equals("---")) { gene = fields[alternateGeneSymbolIndex]; if (StringUtils.isBlank(gene) || gene.equals("---")) { throw new IllegalStateException("Gene name was missing or invalid at line " + n + "; it is possible the file format is not readable; contact the developers."); } } if (activeGenes != null && !activeGenes.contains(gene)) { continue; } // log.debug("Probe=" + probe + " Gene=" + gene); // PP temporary for user problems. storeProbeAndGene(probeIds, probe, gene); /* read gene description */ String description = fields[geneNameIndex].intern(); if (!description.startsWith("GO:")) { this.probeToDescription.put(probe.intern(), description.intern()); } else { this.probeToDescription.put(probe.intern(), NO_DESCRIPTION); } /* * Each field is like this: 0000166 // nucleotide binding // inferred from electronic annotation */ classIds = " // " + fields[goBpIndex] + " // " + fields[goMfIndex] + " // " + fields[goCcIndex]; String[] goinfo = classIds.split("/+"); for (String element : goinfo) { if (StringUtils.isBlank(element)) { continue; } element = StringUtils.strip(element); parseGoTerm(probe, pat, element); } if (messenger != null && n % 5000 == 0) { messenger.showStatus("Read " + n + " probes"); try { Thread.sleep(10); } catch (InterruptedException e) { dis.close(); throw new RuntimeException("Interrupted"); } } n++; } /* Fill in the genegroupreader and the classmap */ dis.close(); tick(); resetSelectedProbes(); if (this.probeToGeneName.size() == 0 || this.geneSetToProbeMap.size() == 0) { throw new IllegalArgumentException( "The gene annotations had invalid information. Please check the format."); } }
From source file:org.apache.hadoop.chukwa.database.Macro.java
public String computeMacro(String macro) throws SQLException { Pattern p = Pattern.compile("past_(.*)_minutes"); Matcher matcher = p.matcher(macro); if (macro.indexOf("avg(") == 0 || macro.indexOf("group_avg(") == 0 || macro.indexOf("sum(") == 0) { String meta = ""; String[] table = null;// ww w . j a va 2s .co m if (forCharting) { table = dbc.findTableNameForCharts(macro.substring(macro.indexOf("(") + 1, macro.indexOf(")")), start, end); } else { table = dbc.findTableName(macro.substring(macro.indexOf("(") + 1, macro.indexOf(")")), start, end); } try { String cluster = System.getProperty("CLUSTER"); if (cluster == null) { cluster = "unknown"; } db = new DatabaseWriter(cluster); DatabaseMetaData dbMetaData = db.getConnection().getMetaData(); ResultSet rs = dbMetaData.getColumns(null, null, table[0], null); boolean first = true; while (rs.next()) { if (!first) { meta = meta + ","; } String name = rs.getString(4); int type = rs.getInt(5); if (type == java.sql.Types.VARCHAR) { if (macro.indexOf("group_avg(") < 0) { meta = meta + "count(" + name + ") as " + name; } else { meta = meta + name; } first = false; } else if (type == java.sql.Types.DOUBLE || type == java.sql.Types.FLOAT || type == java.sql.Types.INTEGER) { if (macro.indexOf("sum(") == 0) { meta = meta + "sum(" + name + ")"; } else { meta = meta + "avg(" + name + ")"; } first = false; } else if (type == java.sql.Types.TIMESTAMP) { meta = meta + name; first = false; } else { if (macro.indexOf("sum(") == 0) { meta = meta + "SUM(" + name + ")"; } else { meta = meta + "AVG(" + name + ")"; } first = false; } } db.close(); if (first) { throw new SQLException("Table is undefined."); } } catch (SQLException ex) { throw new SQLException("Table does not exist:" + table[0]); } return meta; } else if (macro.indexOf("now") == 0) { SimpleDateFormat sdf = new SimpleDateFormat(); return DatabaseWriter.formatTimeStamp(current); } else if (macro.intern() == "start".intern()) { return DatabaseWriter.formatTimeStamp(start); } else if (macro.intern() == "end".intern()) { return DatabaseWriter.formatTimeStamp(end); } else if (matcher.find()) { int period = Integer.parseInt(matcher.group(1)); long timestamp = current - (current % (period * 60 * 1000L)) - (period * 60 * 1000L); return DatabaseWriter.formatTimeStamp(timestamp); } else if (macro.indexOf("past_hour") == 0) { return DatabaseWriter.formatTimeStamp(current - 3600 * 1000L); } else if (macro.endsWith("_week")) { long partition = current / DatabaseConfig.WEEK; if (partition <= 0) { partition = 1; } String[] buffers = macro.split("_"); StringBuffer tableName = new StringBuffer(); for (int i = 0; i < buffers.length - 1; i++) { tableName.append(buffers[i]); tableName.append("_"); } tableName.append(partition); tableName.append("_week"); return tableName.toString(); } else if (macro.endsWith("_month")) { long partition = current / DatabaseConfig.MONTH; if (partition <= 0) { partition = 1; } String[] buffers = macro.split("_"); StringBuffer tableName = new StringBuffer(); for (int i = 0; i < buffers.length - 1; i++) { tableName.append(buffers[i]); tableName.append("_"); } tableName.append(partition); tableName.append("_month"); return tableName.toString(); } else if (macro.endsWith("_quarter")) { long partition = current / DatabaseConfig.QUARTER; if (partition <= 0) { partition = 1; } String[] buffers = macro.split("_"); StringBuffer tableName = new StringBuffer(); for (int i = 0; i < buffers.length - 1; i++) { tableName.append(buffers[i]); tableName.append("_"); } tableName.append(partition); tableName.append("_quarter"); return tableName.toString(); } else if (macro.endsWith("_year")) { long partition = current / DatabaseConfig.YEAR; if (partition <= 0) { partition = 1; } String[] buffers = macro.split("_"); StringBuffer tableName = new StringBuffer(); for (int i = 0; i < buffers.length - 1; i++) { tableName.append(buffers[i]); tableName.append("_"); } tableName.append(partition); tableName.append("_year"); return tableName.toString(); } else if (macro.endsWith("_decade")) { long partition = current / DatabaseConfig.DECADE; if (partition <= 0) { partition = 1; } String[] buffers = macro.split("_"); StringBuffer tableName = new StringBuffer(); for (int i = 0; i < buffers.length - 1; i++) { tableName.append(buffers[i]); tableName.append("_"); } tableName.append(partition); tableName.append("_decade"); return tableName.toString(); } if (forCharting) { if (macro.startsWith("session(") && request != null) { String keyword = macro.substring(macro.indexOf("(") + 1, macro.indexOf(")")); String[] objects = null; if (request.getSession().getAttribute(keyword) != null) { objects = ((String) request.getSession().getAttribute(keyword)).split(","); } StringBuffer buf = new StringBuffer(); boolean first = true; if (objects != null) { for (String object : objects) { if (!first) { buf.append(" or "); } first = false; buf.append( macro.substring(macro.indexOf("(") + 1, macro.indexOf(")")) + "='" + object + "'"); } return buf.toString(); } return ""; } else { String[] tableList = dbc.findTableNameForCharts(macro, start, end); StringBuffer buf = new StringBuffer(); boolean first = true; for (String table : tableList) { if (!first) { buf.append("|"); } first = false; buf.append(table); } return buf.toString(); } } String[] tableList = dbc.findTableName(macro, current, current); return tableList[0]; }