List of usage examples for java.text CharacterIterator next
public char next();
From source file:org.codehaus.mojo.jsimport.AbstractImportMojo.java
private void writeTokenStream(CharStream cs, CommonTokenStream tokenStream, File outputFile) throws IOException { OutputStream os = new BufferedOutputStream(FileUtils.openOutputStream(outputFile)); try {/*from w ww. jav a 2 s. co m*/ List<?> tokens = tokenStream.getTokens(); cs.seek(0); for (Object tokenObject : tokens) { CommonToken token = (CommonToken) tokenObject; if (token.getType() == ECMAScriptLexer.MODULE_DECL || token.getType() == ECMAScriptLexer.REQUIRE_DECL) { int startIndex = token.getStartIndex(); while (cs.index() < startIndex) { int streamChar = cs.LA(1); if (streamChar == CharStream.EOF) { break; } os.write(streamChar); cs.consume(); } CharacterIterator iter = new StringCharacterIterator(token.getText()); for (char tokenChar = iter.first(); tokenChar != CharacterIterator.DONE; tokenChar = iter .next()) { os.write(tokenChar); } cs.seek(token.getStopIndex() + 1); } } int streamChar; while ((streamChar = cs.LA(1)) != CharStream.EOF) { os.write(streamChar); cs.consume(); } } finally { os.close(); } }
From source file:stg.utils.RandomStringGenerator.java
/** * Generates the random string as per the format. * // www . j a v a 2s . c o m * @return String */ public String generate() { CharacterIterator iter = new StringCharacterIterator(format); char c = iter.first(); StringBuilder sb = new StringBuilder(); List<Character> tempLowerCaseCharsList = cloneList(lowerCaseCharsList); List<Character> tempUpperCaseCharsList = cloneList(upperCaseCharsList); List<Character> tempNumericCharsList = cloneList(numericCharsList); List<Character> tempSpecialCharsList = cloneList(specialCharsList); boolean constantStarted = false; while (c != CharacterIterator.DONE) { switch (c) { case ESCAPE: c = iter.next(); if (c == CharacterIterator.DONE) { throw new IllegalArgumentException( "Invalid format, escape character found without any associated character that was to be escaped."); } sb.append(c); break; case LOWER_CASE: if (!constantStarted) { switch (option) { case NON_UNIQUE: sb.append(RandomStringUtils.random(1, toCharArray(lowerCaseCharsList))); break; case UNIQUE_CASE_SENSITIVE: sb.append(generateUniqueCharacter(c, tempLowerCaseCharsList)); break; default: String str = generateUniqueCharacter(c, tempLowerCaseCharsList); sb.append(str); if (!tempUpperCaseCharsList.contains(Character.valueOf(str.toUpperCase().charAt(0)))) { System.out.println(tempLowerCaseCharsList + " \t " + str); } if (!tempUpperCaseCharsList.remove(Character.valueOf(str.toUpperCase().charAt(0)))) { //remove it from the upper case char set. System.out.println("Problem unable to remove " + tempUpperCaseCharsList + "\t" + str); } break; } } else { sb.append(c); } break; case UPPER_CASE: if (!constantStarted) { switch (option) { case NON_UNIQUE: sb.append(RandomStringUtils.random(1, toCharArray(upperCaseCharsList))); break; case UNIQUE_CASE_SENSITIVE: sb.append(generateUniqueCharacter(c, tempUpperCaseCharsList)); break; default: String str = generateUniqueCharacter(c, tempUpperCaseCharsList); sb.append(str); if (!tempLowerCaseCharsList.contains(Character.valueOf(str.toLowerCase().charAt(0)))) { System.out.println(tempLowerCaseCharsList + " \t " + str); } if (!tempLowerCaseCharsList.remove(Character.valueOf(str.toLowerCase().charAt(0)))) { System.out.println("Problem unable to remove " + tempLowerCaseCharsList + "\t" + str); } break; } } else { sb.append(c); } break; case NUMBER: if (!constantStarted) { switch (option) { case NON_UNIQUE: sb.append(RandomStringUtils.random(1, toCharArray(numericCharsList))); break; default: sb.append(generateUniqueCharacter(c, tempNumericCharsList)); break; } } else { sb.append(c); } break; case SPECIAL: if (!constantStarted) { switch (option) { case NON_UNIQUE: sb.append(RandomStringUtils.random(1, toCharArray(specialCharsList))); break; default: sb.append(generateUniqueCharacter(c, tempSpecialCharsList)); break; } } else { sb.append(c); } break; case START_CONSTANT: if (constantStarted) { throw new IllegalArgumentException("Special { character found without an escape character"); } if (!constantStarted) constantStarted = true; break; case END_CONSTANT: if (!constantStarted) throw new IllegalArgumentException("Special } character found without an escape character"); if (constantStarted) constantStarted = false; break; default: sb.append(c); } c = iter.next(); } return sb.toString(); }
From source file:net.pms.encoders.FFmpegVideo.java
/** * Returns a list of strings representing the rescale options for this transcode i.e. the ffmpeg -vf * options used to show subtitles in SSA/ASS format and resize a video that's too wide and/or high for the specified renderer. * If the renderer has no size limits, or there's no media metadata, or the video is within the renderer's * size limits, an empty list is returned. * * @param dlna The DLNA resource representing the file being transcoded. * @param media the media metadata for the video being streamed. May contain unset/null values (e.g. for web videos). * @param params The {@link net.pms.io.OutputParams} context object used to store miscellaneous parameters for this request. * @return a {@link List} of <code>String</code>s representing the rescale options for this video, * or an empty list if the video doesn't need to be resized. *//* ww w.j a v a2 s .c o m*/ public List<String> getVideoFilterOptions(DLNAResource dlna, DLNAMediaInfo media, OutputParams params) throws IOException { List<String> options = new ArrayList<String>(); String subsOption = null; String padding = null; final RendererConfiguration renderer = params.mediaRenderer; DLNAMediaSubtitle tempSubs = null; if (!isDisableSubtitles(params)) { tempSubs = getSubtitles(params); } final boolean isResolutionTooHighForRenderer = renderer.isVideoRescale() // renderer defines a max width/height && (media != null && media.isMediaparsed()) && ((media.getWidth() > renderer.getMaxVideoWidth()) || (media.getHeight() > renderer.getMaxVideoHeight())); if (tempSubs != null) { StringBuilder s = new StringBuilder(); CharacterIterator it = new StringCharacterIterator( ProcessUtil.getShortFileNameIfWideChars(tempSubs.getExternalFile().getAbsolutePath())); for (char ch = it.first(); ch != CharacterIterator.DONE; ch = it.next()) { switch (ch) { case ':': s.append("\\\\:"); break; case '\\': s.append("/"); break; case ']': s.append("\\]"); break; case '[': s.append("\\["); break; default: s.append(ch); } } String subsFile = s.toString(); subsFile = subsFile.replace(",", "\\,"); subsOption = "subtitles=" + subsFile; } if (renderer.isPadVideoWithBlackBordersTo169AR() && renderer.isRescaleByRenderer()) { if (media != null && media.isMediaparsed() && media.getHeight() != 0 && (media.getWidth() / (double) media.getHeight()) >= (16 / (double) 9)) { padding = "pad=iw:iw/(16/9):0:(oh-ih)/2"; } else { padding = "pad=ih*(16/9):ih:(ow-iw)/2:0"; } } String rescaleSpec = null; if (isResolutionTooHighForRenderer || (renderer.isPadVideoWithBlackBordersTo169AR() && !renderer.isRescaleByRenderer())) { rescaleSpec = String.format( // http://stackoverflow.com/a/8351875 "scale=iw*min(%1$d/iw\\,%2$d/ih):ih*min(%1$d/iw\\,%2$d/ih),pad=%1$d:%2$d:(%1$d-iw)/2:(%2$d-ih)/2", renderer.getMaxVideoWidth(), renderer.getMaxVideoHeight()); } String overrideVF = renderer.getFFmpegVideoFilterOverride(); if (rescaleSpec != null || padding != null || overrideVF != null || subsOption != null) { options.add("-vf"); StringBuilder filterParams = new StringBuilder(); if (overrideVF != null) { filterParams.append(overrideVF); if (subsOption != null) { filterParams.append(", "); } } else { if (rescaleSpec != null) { filterParams.append(rescaleSpec); if (subsOption != null || padding != null) { filterParams.append(", "); } } if (padding != null && rescaleSpec == null) { filterParams.append(padding); if (subsOption != null) { filterParams.append(", "); } } } if (subsOption != null) { filterParams.append(subsOption); } options.add(filterParams.toString()); } return options; }
From source file:de.innovationgate.utils.WGUtils.java
/** * Clears out "internal strings" from a text that contains some kind of * program code. I.e. if the text itself contains string delimiter * characters, like " or ', the contents between these characters is * regarded a string. Its contents will be cleared in the text version that * is returned by this method. This is useful to prepare a text for an * operation, that may not react on the contents of strings inside it. This * method regards the character \ as an escape sign for string delimiters. * So delimiter characters that are prefixed by a \ will be ignored. * //from w ww . j a v a 2s. c o m * @param colString * The text * @param stringDelimiter * The character that introduces and closes strings inside the * text * @param replaceChar * The character that is used to clear out strings. * @return The text with cleared out internal strings */ public static String clearStrings(String colString, char stringDelimiter, char replaceChar) { CharacterIterator it = new StringCharacterIterator(colString); StringBuffer out = new StringBuffer(); boolean inAString = false; char prevChar = ' '; for (char c = it.first(); c != CharacterIterator.DONE; c = it.next()) { // Look for string introducor if (c == stringDelimiter && prevChar != '\\') { inAString = !inAString; out.append(stringDelimiter); } else if (inAString) { out.append(replaceChar); } else { out.append(c); } prevChar = c; } return out.toString(); }