Java File Append appendToken(StringBuilder path, String token, boolean skipEmpty, boolean skipSeparator)

Here you can find the source of appendToken(StringBuilder path, String token, boolean skipEmpty, boolean skipSeparator)

Description

append Token

License

Open Source License

Declaration

private static void appendToken(StringBuilder path, String token, boolean skipEmpty, boolean skipSeparator) 

Method Source Code


//package com.java2s;
/*//  ww w. j  a  v  a2s  .  com
 * Copyright (c) 2015 The original author or authors.
 *
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Apache License v2.0
 *  which accompanies this distribution.
 *
 *  The Apache License v2.0 is available at
 *  http://opensource.org/licenses/Apache-2.0
 *
 *  You may elect to redistribute this code under this license.
 */

import java.io.File;

public class Main {
    private static void appendToken(StringBuilder path, String token, boolean skipEmpty, boolean skipSeparator) {
        if (skipEmpty && (token == null || token.length() == 0)) {
            // If this is the last token, remove the leading file separator
            if (skipSeparator) {
                path.replace(path.length() - 1, path.length(), "");
            }
            return;
        }

        path.append(token);
        if (!skipSeparator)
            path.append(File.separator);
    }
}

Related

  1. appendTo(String fileName, String str)
  2. appendTo(StringBuffer sb, CharSequence s)
  3. appendToArray(final File[] original, final File[] toAppend)
  4. appendToCollection(final Vector original, final File[] toAppend)
  5. appendToFileName(File file, String str)
  6. appendToOutput(InputStream input, OutputStream output)
  7. appendToOutputStream(OutputStream out, String value)