List of usage examples for java.lang Character toString
public static String toString(int codePoint)
From source file:gephi.spade.panel.fcsFile.java
/** * readFile ---/* ww w. j a v a 2 s . c o m*/ * <p> * A helper function to read all the fields in the TEXT segment of the FCS * file. * </p> * * <p> * This helper function should only be called once by the constructor as it * is quite expensive. * </p> * * @param extractEventsP * boolean flag indicating whether to extract events in the * underlying file. * @throws <code>java.io.FileNotFoundException</code> if the file is not * found. * @throws <code>java.io.IOException</code> if an IO exception occurred. */ private void readFile(boolean extractEventsP) throws FileNotFoundException, IOException { // Open a file input stream to the file FileInputStream fis = new FileInputStream(file); // Create a byte array to hold the version byte[] versionArray = new byte[VERSION_SIZE]; // Read the version into the byte array int numRead = fis.read(versionArray); if (numRead < VERSION_SIZE) { // If the number of bytes read is less than the number of bytes in // the version string, then the file is too small to be an FCS file. isFCSP = false; // Close the file input stream fis.close(); // Quit return; } // Decode the version using the default encoding version = new String(versionArray); // Determine whether the file is an FCS file by whether the version // string starts with the FCS_PREFIX isFCSP = version.startsWith(FCS_PREFIX); if (!isFCSP) { // If the file is not an FCS file, then close the file and quit. // Close the file input stream fis.close(); // Quit return; } /** * At this point, we are pretty sure that the file is an FCS file. So, * we parse it. */ /** * Get the standard HEADER stuff */ // Skip 4 bytes to get to byte 10 fis.skip(4); // Create a byte array to hold the HEADER byte[] headerArray = new byte[48]; // Read the header into the byte array numRead = fis.read(headerArray); if (numRead < 48) { // If the number of bytes read is less than 48, then the file is too // small to be an FCS file. isFCSP = false; // Close the file input stream fis.close(); // Quit return; } try { // Try to parse the TEXT segment start and end and DATA segment // start and end textStart = Integer.parseInt((new String(headerArray, 0, 8)).trim()); textEnd = Integer.parseInt((new String(headerArray, 8, 8)).trim()); dataStart = Integer.parseInt((new String(headerArray, 16, 8)).trim()); dataEnd = Integer.parseInt((new String(headerArray, 24, 8)).trim()); } catch (NumberFormatException nfe) { // If a NumberFormatException occured, then quit because there's // nothing we can do without the TEXT or DATA segment. // Close the file input stream fis.close(); return; } /** * Get the ANALYSIS segment limits */ try { // Try to parse the analysisStart and analysisEnd analysisStart = Integer.parseInt((new String(headerArray, 32, 8)).trim()); analysisEnd = Integer.parseInt((new String(headerArray, 40, 8)).trim()); } catch (NumberFormatException nfe) { // If a NumberFormatException occured, then set the ANALYSIS start // and end to 0 since this segment is optional. analysisStart = 0; analysisEnd = 0; } /** * Use NIO to read the OTHER and TEXT segments */ // Get the channel for the input file FileChannel fc = fis.getChannel(); // Move the channel's position back to 0 fc.position(0); // Map the TEXT segment to memory MappedByteBuffer mbb = fc.map(FileChannel.MapMode.READ_ONLY, 0, textEnd + 1); /** * Create the character decoder for parsing characters */ decoder = charset.newDecoder(); /** * Get the OTHER segment */ mbb.limit(textStart); mbb.position(58); CharBuffer other = decoder.decode(mbb.slice()); /** * Get the TEXT segment */ mbb.limit(textEnd + 1); mbb.position(textStart); text = decoder.decode(mbb.slice()).toString(); /** * Close the file since we have the string version of the TEXT segment */ // Close the file channel fc.close(); // Close the file input stream fis.close(); /** * Decode the TEXT segment */ // The first character of the primary TEXT segment contains the // delimiter character delimiter = text.charAt(0); /** * Key/Value Pairs */ // Generate all the pairs String[] pairs; if (delimiter == '\\') { // If the delimiter character is a backslash, then we have to escape // it in the regular expression. pairs = text.split("[\\\\]"); } else { // Otherwise, we can just split it normally by using the character // in the regular expression. pairs = text.split("[" + Character.toString(delimiter) + "]"); } /** * Calculate the number of pairs --- The number of pairs is the length * of the pairs array minus 1 divided by 2. The one is due to the empty * first element from the Java split above. */ int numPairs = (pairs.length - 1) / 2; // Create a mapping for each key and its value settings = new Properties(); // Loop through the TEXT segment we just split to get the keys and // values // The key is in (i * 2) + 1 to account for the empty first element. // The value is in (i * 2) + 2 to account for the empty first element. for (int i = 0; i < numPairs; i++) { settings.setProperty(pairs[(i * 2) + 1].trim(), pairs[(i * 2) + 2].trim()); } // Go through all the key/value pairs and parse them parseSettings(); /** * Extract Events */ if (extractEventsP) { // If we are extracting data, then do so. extractEvents(); } }
From source file:org.apache.hive.hcatalog.api.HCatTable.java
/** * See <i>row_format</i> element of CREATE_TABLE DDL for Hive. *//*from w ww . ja va2s .com*/ public HCatTable fieldsTerminatedBy(char delimiter) { return serdeParam(serdeConstants.FIELD_DELIM, Character.toString(delimiter)); }
From source file:org.dspace.app.xmlui.aspect.artifactbrowser.ConfigurableBrowse.java
/** * Makes the jump-list navigation for the results * * @param div/*from ww w .ja va2 s . c om*/ * @param info * @param params * @throws WingException */ private void addBrowseJumpNavigation(Division div, BrowseInfo info, BrowseParams params) throws WingException { // Prepare a Map of query parameters required for all links Map<String, String> queryParamsGET = new HashMap<String, String>(); queryParamsGET.putAll(params.getCommonParametersEncoded()); queryParamsGET.putAll(params.getControlParameters()); Map<String, String> queryParamsPOST = new HashMap<String, String>(); queryParamsPOST.putAll(params.getCommonParameters()); queryParamsPOST.putAll(params.getControlParameters()); // Navigation aid (really this is a poor version of pagination) Division jump = div.addInteractiveDivision("browse-navigation", BROWSE_URL_BASE, Division.METHOD_POST, "secondary navigation"); // Add all the query parameters as hidden fields on the form for (Map.Entry<String, String> param : queryParamsPOST.entrySet()) { jump.addHidden(param.getKey()).setValue(param.getValue()); } // If this is a date based browse, render the date navigation if (isSortedByDate(info)) { Para jumpForm = jump.addPara(); // Create a select list to choose a month jumpForm.addContent(T_jump_select); Select month = jumpForm.addSelect(BrowseParams.MONTH); month.addOption(false, "-1", T_choose_month); for (int i = 1; i <= 12; i++) { month.addOption(false, String.valueOf(i), DCDate.getMonthName(i, Locale.getDefault())); } // Create a select list to choose a year Select year = jumpForm.addSelect(BrowseParams.YEAR); year.addOption(false, "-1", T_choose_year); int currentYear = DCDate.getCurrent().getYear(); int i = currentYear; // Calculate where to move from 1, 5 to 10 year jumps int oneYearBreak = ((currentYear - ONE_YEAR_LIMIT) / 5) * 5; int fiveYearBreak = ((currentYear - FIVE_YEAR_LIMIT) / 10) * 10; int tenYearBreak = (currentYear - TEN_YEAR_LIMIT); do { year.addOption(false, String.valueOf(i), String.valueOf(i)); if (i <= fiveYearBreak) { i -= 10; } else if (i <= oneYearBreak) { i -= 5; } else { i--; } } while (i > tenYearBreak); // Create a free text entry box for the year jumpForm = jump.addPara(); jumpForm.addContent(T_jump_year); jumpForm.addText(BrowseParams.STARTS_WITH).setHelp(T_jump_year_help); jumpForm.addButton("submit").setValue(T_go); } else { // Create a clickable list of the alphabet List jumpList = jump.addList("jump-list", List.TYPE_SIMPLE, "alphabet"); // browse params for each letter are all the query params // WITHOUT the second-stage browse value, and add STARTS_WITH. Map<String, String> letterQuery = new HashMap<String, String>(queryParamsGET); for (String valueKey : BrowseParams.FILTER_VALUE) { letterQuery.remove(valueKey); } letterQuery.put(BrowseParams.STARTS_WITH, "0"); jumpList.addItemXref(super.generateURL(BROWSE_URL_BASE, letterQuery), "0-9"); for (char c = 'A'; c <= 'Z'; c++) { letterQuery.put(BrowseParams.STARTS_WITH, Character.toString(c)); jumpList.addItemXref(super.generateURL(BROWSE_URL_BASE, letterQuery), Character.toString(c)); } // Create a free text field for the initial characters Para jumpForm = jump.addPara(); jumpForm.addContent(T_starts_with); jumpForm.addText(BrowseParams.STARTS_WITH).setHelp(T_starts_with_help); jumpForm.addButton("submit").setValue(T_go); } }
From source file:edu.internet2.middleware.subject.provider.JNDISourceAdapter.java
/** * Escape a search filter to prevent LDAP injection. * From http://www.owasp.org/index.php/Preventing_LDAP_Injection_in_Java * /*w w w .ja v a 2 s .com*/ * @param filter * @return escaped filter */ protected String escapeSearchFilter(String filter) { //From RFC 2254 String escapedStr = new String(filter); escapedStr = escapedStr.replaceAll("\\\\", "\\\\5c"); // We want people to be able to use wildcards. // escapedStr = escapedStr.replaceAll("\\*","\\\\2a"); escapedStr = escapedStr.replaceAll("\\(", "\\\\28"); escapedStr = escapedStr.replaceAll("\\)", "\\\\29"); escapedStr = escapedStr.replaceAll("\\" + Character.toString('\u0000'), "\\\\00"); return escapedStr; }
From source file:gov.nih.nci.cabig.caaers.web.admin.CTEPDataInitializationAjaxFacade.java
private String getServiceNameFromEntityAndOperation(String entity, String operation) { if (operation.equalsIgnoreCase("updateStudy") || operation.equalsIgnoreCase("createStudy")) { return "GetStudyDetails"; }/*from ww w . ja va 2 s . co m*/ StringBuffer serviceName = new StringBuffer( Character.toString((Character.toUpperCase(operation.charAt(0))))); serviceName.append(operation.substring(1)); return serviceName.toString(); }
From source file:com.alibaba.citrus.service.requestcontext.support.ValueListSupport.java
/** * ???/? * * @param value ? */ public void addValue(char value) { addValue(Character.toString(value)); }
From source file:org.apache.hive.hcatalog.api.HCatTable.java
/** * See <i>row_format</i> element of CREATE_TABLE DDL for Hive. *///w w w . j ava 2 s.c o m public HCatTable escapeChar(char escapeChar) { return serdeParam(serdeConstants.ESCAPE_CHAR, Character.toString(escapeChar)); }
From source file:org.codehaus.enunciate.modules.xfire.EnunciatedJAXWSOperationBinding.java
/** * Capitalizes a string./*www . j av a2s .c o m*/ * * @param string The string to capitalize. * @return The capitalized value. */ private String capitalize(String string) { return Character.toString(string.charAt(0)).toUpperCase() + string.substring(1); }
From source file:edu.cornell.med.icb.goby.modes.MethylationRateVCFOutputFormat.java
@Override public void writeRecord(final DiscoverVariantIterateSortedAlignments iterator, final SampleCountInfo[] sampleCounts, final int referenceIndex, int position, final DiscoverVariantPositionData list, final int groupIndexA, final int groupIndexB) { final int oneBasedPosition = position + 1; final char refBase = sampleCounts[0].referenceBase; if (refBase != 'C' && refBase != 'G') { mci.reset();//from w w w.ja va 2 s . c om return; } fillMethylationCountArrays(sampleCounts, list, oneBasedPosition, refBase, mci, readerIndexToGroupIndex); doEmpiricalP(mci, referenceIndex, position); if (estimateIntraGroupDifferences) { return; } if (mci.eventCountAtSite < minimumEventThreshold) { return; } statWriter.setInfo(depthFieldIndex, list.size()); final CharSequence currentReferenceId = iterator.getReferenceId(referenceIndex); statWriter.setChromosome(currentReferenceId); statWriter.setPosition(oneBasedPosition); statWriter.setReferenceAllele(Character.toString(sampleCounts[0].referenceBase)); // construct a biomart region span in the format chr:pos1:chr:pos final String biomartRegionSpan = String.format("%s:%s:%s", currentReferenceId, oneBasedPosition, oneBasedPosition); statWriter.setInfo(biomartFieldIndex, biomartRegionSpan); statWriter.setInfo(strandFieldIndex, Character.toString(mci.strandAtSite)); final String genomicContext = findGenomicContext(genomeReferenceIndex, oneBasedPosition); statWriter.setInfo(genomicContextIndex, genomicContext); for (int groupIndex = 0; groupIndex < numberOfGroups; groupIndex++) { statWriter.setInfo(notMethylatedCCountsIndex[groupIndex], mci.unmethylatedCCountPerGroup[groupIndex]); statWriter.setInfo(methylatedCCountsIndex[groupIndex], mci.methylatedCCountPerGroup[groupIndex]); statWriter.setInfo(methylationRatePerGroupIndex[groupIndex], getMR(groupIndex)); } for (int sampleIndex = 0; sampleIndex < numberOfSamples; sampleIndex++) { final float numerator = mci.methylatedCCountPerSample[sampleIndex]; final float denominator = numerator + mci.unmethylatedCCountPerSample[sampleIndex]; final float methylationRate = numerator * 100 / denominator; statWriter.setSampleValue(methylationRateFieldIndex, sampleIndex, Math.round(methylationRate)); statWriter.setSampleValue(unconvertedCytosineFieldIndex, sampleIndex, mci.methylatedCCountPerSample[sampleIndex]); statWriter.setSampleValue(convertedCytosineFieldIndex, sampleIndex, mci.unmethylatedCCountPerSample[sampleIndex]); } for (final GroupComparison comparison : groupComparisons) { final int indexGroup1 = comparison.indexGroup1; final int indexGroup2 = comparison.indexGroup2; final double denominator = (double) (mci.unmethylatedCCountPerGroup[indexGroup1]) * (double) (mci.methylatedCCountPerGroup[indexGroup2]); final double oddsRatio = denominator == 0 ? Double.NaN : ((double) (mci.unmethylatedCCountPerGroup[indexGroup2]) * (double) (mci.methylatedCCountPerGroup[indexGroup1])) / denominator; final double logOddsRatioSE; if (mci.methylatedCCountPerGroup[indexGroup1] < 10 || mci.methylatedCCountPerGroup[indexGroup2] < 10 || mci.unmethylatedCCountPerGroup[indexGroup1] < 10 || mci.unmethylatedCCountPerGroup[indexGroup2] < 10) { // standard error estimation is unreliable when any of the counts are less than 10. logOddsRatioSE = Double.NaN; } else { logOddsRatioSE = Math.sqrt(1d / mci.unmethylatedCCountPerGroup[indexGroup2] + 1d / mci.methylatedCCountPerGroup[indexGroup1] + 1d / mci.methylatedCCountPerGroup[indexGroup2] + 1d / mci.unmethylatedCCountPerGroup[indexGroup1]); } final double log2OddsRatio = Math.log(oddsRatio) / Math.log(2); final double log2OddsRatioZValue = log2OddsRatio / logOddsRatioSE; double fisherP = Double.NaN; if (mci.eventCountAtSite >= minimumEventThreshold) { // estimate Fisher only if we have seen at least 10 events. final boolean ok = checkCounts(); if (ok) { fisherP = fisherRInstalled ? FisherExactRCalculator.getFisherPValue( mci.unmethylatedCCountPerGroup[indexGroup2], mci.methylatedCCountPerGroup[indexGroup2], mci.unmethylatedCCountPerGroup[indexGroup1], mci.methylatedCCountPerGroup[indexGroup1]) : Double.NaN; } else { System.err.printf( "An exception was caught evaluating the Fisher Exact test P-value. Details are provided below%n" + "referenceId=%s referenceIndex=%d position=%d %n" + "unmethylatedCCountsPerGroup[1]=%d methylatedCCountPerGroup[1]=%d%n" + "unmethylatedCCountsPerGroup[0]=%d, methylatedCCountPerGroup[0]=%d", currentReferenceId, referenceIndex, position, mci.unmethylatedCCountPerGroup[indexGroup2], mci.methylatedCCountPerGroup[indexGroup2], mci.unmethylatedCCountPerGroup[indexGroup1], mci.methylatedCCountPerGroup[indexGroup1]); } } final double group1MR = getMR(indexGroup1); final double group2MR = getMR(indexGroup2); final int deltaMR = (int) Math.round(Math.abs(group1MR - group2MR)); statWriter.setInfo(log2OddsRatioColumnIndex[comparison.index], log2OddsRatio); statWriter.setInfo(log2OddsRatioStandardErrorColumnIndex[comparison.index], logOddsRatioSE); statWriter.setInfo(log2OddsRatioZColumnIndex[comparison.index], log2OddsRatioZValue); statWriter.setInfo(fisherExactPValueColumnIndex[comparison.index], fisherP); statWriter.setInfo(deltaMRColumnIndex[comparison.index], deltaMR); } genotypeFormatter.writeGenotypes(statWriter, sampleCounts, oneBasedPosition); for (int sampleIndex = 0; sampleIndex < numberOfSamples; sampleIndex++) { final int firstIndex = sampleIndex; final int secondIndex = convertIndex(sampleIndex, mci.strandAtSite); if (mci.strandAtSite == '+') { final int otherIndex = convertIndex(sampleIndex, '-'); statWriter.setSampleValue(methylationRateFieldIndex, otherIndex, "100"); statWriter.setSampleValue(convertedCytosineFieldIndex, otherIndex, "0"); statWriter.setSampleValue(unconvertedCytosineFieldIndex, otherIndex, "0"); statWriter.setSampleValue(genotypeFormatter.getGenotypeFieldIndex(), otherIndex, "0/0"); statWriter.setSampleValue(genotypeFormatter.getBaseCountFieldIndex(), otherIndex, "ignore"); statWriter.setSampleValue(genotypeFormatter.getFailBaseCountFieldIndex(), otherIndex, "ignore"); statWriter.setSampleValue(genotypeFormatter.getGoodBaseCountFieldIndex(), otherIndex, "0"); } else { statWriter.switchSampleValue(methylationRateFieldIndex, firstIndex, secondIndex, "100"); statWriter.switchSampleValue(convertedCytosineFieldIndex, firstIndex, secondIndex, "0"); statWriter.switchSampleValue(unconvertedCytosineFieldIndex, firstIndex, secondIndex, "0"); statWriter.switchSampleValue(genotypeFormatter.getGenotypeFieldIndex(), firstIndex, secondIndex, "0/0"); statWriter.switchSampleValue(genotypeFormatter.getBaseCountFieldIndex(), firstIndex, secondIndex, "ignore"); statWriter.switchSampleValue(genotypeFormatter.getFailBaseCountFieldIndex(), firstIndex, secondIndex, "ignore"); statWriter.switchSampleValue(genotypeFormatter.getGoodBaseCountFieldIndex(), firstIndex, secondIndex, "0"); } } statWriter.writeRecord(); }
From source file:org.apache.hive.hcatalog.api.HCatTable.java
/** * See <i>row_format</i> element of CREATE_TABLE DDL for Hive. */// ww w . ja v a2 s. co m public HCatTable collectionItemsTerminatedBy(char delimiter) { return serdeParam(serdeConstants.COLLECTION_DELIM, Character.toString(delimiter)); }