Example usage for java.text CharacterIterator first

List of usage examples for java.text CharacterIterator first

Introduction

In this page you can find the example usage for java.text CharacterIterator first.

Prototype

public char first();

Source Link

Document

Sets the position to getBeginIndex() and returns the character at that position.

Usage

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 {/*  w  w  w  . ja  v  a 2  s.c  om*/
        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: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.
 *//*from w  w  w  .  ja  v a2  s  .  com*/
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.
 * /*w  w w.jav a 2  s.co  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();

}