当前位置: 首页>>代码示例>>Java>>正文


Java Scanner.useDelimiter方法代码示例

本文整理汇总了Java中java.util.Scanner.useDelimiter方法的典型用法代码示例。如果您正苦于以下问题:Java Scanner.useDelimiter方法的具体用法?Java Scanner.useDelimiter怎么用?Java Scanner.useDelimiter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Scanner的用法示例。


在下文中一共展示了Scanner.useDelimiter方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getResponseFromHttpUrl

import java.util.Scanner; //导入方法依赖的package包/类
/**
 * This method returns the entire result from the HTTP response.
 *
 * @param url The URL to fetch the HTTP response from.
 * @return The contents of the HTTP response, null if no response
 * @throws IOException Related to network and stream reading
 */
public static String getResponseFromHttpUrl(URL url) throws IOException {
    HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
    try {
        InputStream in = urlConnection.getInputStream();

        Scanner scanner = new Scanner(in);
        scanner.useDelimiter("\\A");

        boolean hasInput = scanner.hasNext();
        String response = null;
        if (hasInput) {
            response = scanner.next();
        }
        scanner.close();
        return response;
    } finally {
        urlConnection.disconnect();
    }
}
 
开发者ID:fjoglar,项目名称:android-dev-challenge,代码行数:27,代码来源:NetworkUtils.java

示例2: processLine

import java.util.Scanner; //导入方法依赖的package包/类
@Override
protected void processLine(String line) {
    if (!line.contains("=") || line.isEmpty()) {
        return;
    }
    //use a second Scanner to parse the content of each line
    Scanner lineScanner = new Scanner(line);
    lineScanner.useDelimiter("=");
    if (lineScanner.hasNext()) {
        String key = lineScanner.next();
        String value = "";
        if (lineScanner.hasNext()) {
            value = lineScanner.next();
        }
        map.put(key, value);
    }
    //no need to call lineScanner.close(), since the source is a String
}
 
开发者ID:phweda,项目名称:MFM,代码行数:19,代码来源:ParsenPlayerINI.java

示例3: getResponseFromHttpUrl

import java.util.Scanner; //导入方法依赖的package包/类
/**
 * This method returns the entire result from the HTTP response.
 *
 * @param url The URL to fetch the HTTP response from.
 * @return The contents of the HTTP response.
 * @throws IOException Related to network and stream reading
 */
public static String getResponseFromHttpUrl(URL url) throws IOException {
    HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
    try {
        InputStream in = urlConnection.getInputStream();

        Scanner scanner = new Scanner(in);
        scanner.useDelimiter("\\A");

        boolean hasInput = scanner.hasNext();
        if (hasInput) {
            return scanner.next();
        } else {
            return null;
        }
    } finally {
        urlConnection.disconnect();
    }
}
 
开发者ID:fjoglar,项目名称:android-dev-challenge,代码行数:26,代码来源:NetworkUtils.java

示例4: parse

import java.util.Scanner; //导入方法依赖的package包/类
/**
 * Adds all parameters within the Scanner to the list of
 * <code>parameters</code>, as encoded by <code>encoding</code>. For
 * example, a scanner containing the string <code>a=1&b=2&c=3</code> would
 * add the {@link NameValuePair NameValuePairs} a=1, b=2, and c=3 to the
 * list of parameters.
 *
 * @param parameters
 *            List to add parameters to.
 * @param scanner
 *            Input that contains the parameters to parse.
 * @param charset
 *            Encoding to use when decoding the parameters.
 */
public static void parse (
        final List <NameValuePair> parameters,
        final Scanner scanner,
        final String charset) {
    scanner.useDelimiter(PARAMETER_SEPARATOR);
    while (scanner.hasNext()) {
        String name = null;
        String value = null;
        String token = scanner.next();
        int i = token.indexOf(NAME_VALUE_SEPARATOR);
        if (i != -1) {
            name = decodeFormFields(token.substring(0, i).trim(), charset);
            value = decodeFormFields(token.substring(i + 1).trim(), charset);
        } else {
            name = decodeFormFields(token.trim(), charset);
        }
        parameters.add(new BasicNameValuePair(name, value));
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:URLEncodedUtils.java

示例5: read

import java.util.Scanner; //导入方法依赖的package包/类
public void read(Integer[][] array) throws FileNotFoundException {
    Scanner scanner = new Scanner(new File("signal.CSV"));
    int columns = 0;
    int row = 0;
    scanner.useDelimiter("\\D+");
    while (scanner.hasNext()) {
        array[row][columns] = scanner.nextInt();
        columns += 1;
        if (columns == 4) {
            columns = 0;
            row += 1;
        }
        //System.out.println(array[0][0]);
    }


    scanner.close();
}
 
开发者ID:gransort,项目名称:Java-oscilloscope-project,代码行数:19,代码来源:CSVReader.java

示例6: readFromFile

import java.util.Scanner; //导入方法依赖的package包/类
public void readFromFile() throws IOException
{
    Scanner in = new Scanner(new BufferedReader(new FileReader(file)));
    try
    {
        in.useDelimiter(",");
        headerLine = in.nextLine(); // Skip header row
        while (in.hasNextLine())
        {
            String srgName = in.next();
            String mcpName = in.next();
            String side = in.nextLine().substring(1);
            srgParamName2ParamCsvData.put(srgName, new ParamCsvData(srgName, mcpName, Integer.valueOf(side)));
        }
    }
    finally
    {
        in.close();
    }
}
 
开发者ID:fr1kin,项目名称:ForgeHax,代码行数:21,代码来源:ParamCsvFile.java

示例7: getResponseFromHttpUrl

import java.util.Scanner; //导入方法依赖的package包/类
public static String getResponseFromHttpUrl(String url) throws IOException {

        URL urlObject = new URL(url);

        HttpURLConnection urlConnection =
                (HttpURLConnection) urlObject.openConnection();

        try {
            InputStream in = urlConnection.getInputStream();

            Scanner scanner = new Scanner(in);
            scanner.useDelimiter("\\A");

            boolean hasInput = scanner.hasNext();
            if (hasInput) {
                return scanner.next();
            } else {
                return null;
            }
        } finally {
            urlConnection.disconnect();
        }
    }
 
开发者ID:MrNo-Body,项目名称:ecam-app-android,代码行数:24,代码来源:NetworkUtils.java

示例8: initialize

import java.util.Scanner; //导入方法依赖的package包/类
protected void initialize() {
  	try {
	scanner = new Scanner(new File("/home/lvuser/recordedMacro_" + macroName + ".csv"));
	scanner.useDelimiter(",|\\n");
} catch (FileNotFoundException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
  	timer.start();
  	System.out.println("playing macro " + macroName);
  }
 
开发者ID:frc2879,项目名称:2017-newcomen,代码行数:12,代码来源:PlayMacro.java

示例9: LevelDefinition

import java.util.Scanner; //导入方法依赖的package包/类
/**
 * Create a new LevelDefinition by data and type.
 *
 * @param in
 *            the input data (e.g. from file) of the level
 * @param type
 *            the type of the level
 */
public LevelDefinition(InputStream in, LevelType type) {
	this.type = type;
	Scanner scanner = new Scanner(in, Charset.defaultCharset().name());
	scanner.useDelimiter("\\A");
	String input = scanner.hasNext() ? scanner.next() : "";
	scanner.close();

	LevelParser.parseLevel(input, this);
	this.name = this.calcName();
	this.arcadeNum = -1;
}
 
开发者ID:rekit-group,项目名称:rekit-game,代码行数:20,代码来源:LevelDefinition.java

示例10: isBlockedPacket

import java.util.Scanner; //导入方法依赖的package包/类
private boolean isBlockedPacket(String channel, PacketBuffer buffer) {
    if(IGNORE_LIST.contains(channel)) {
        return true;
    } else if("REGISTER".equals(channel)) {
        Scanner scanner = new Scanner(new String(buffer.array()));
        scanner.useDelimiter("\\u0000");
        if(scanner.hasNext()) {
            String next = scanner.next();
            if(!Strings.isNullOrEmpty(next) && IGNORE_LIST.contains(next)) return true;
        }
    }
    return false;
}
 
开发者ID:fr1kin,项目名称:ForgeHax,代码行数:14,代码来源:PayloadSpoofer.java

示例11: evaluate

import java.util.Scanner; //导入方法依赖的package包/类
public static String evaluate(String templateString, Map<String, Object> environment) {
    final Scanner s = new Scanner(templateString);
    // TODO: This is a hack that fails if a string literal contains "}"
    // TODO: It's because i couldn't be bothered nesting grammars.
    s.useDelimiter("((?!\\\\)\\$\\{)|(})");

    StringBuilder ret = new StringBuilder();
    boolean isInsideExpr = templateString.startsWith("${");
    while(s.hasNext()) {
        final String str = s.next();

        if (isInsideExpr) {
            final JsLikeExpressionLexer lexer = new JsLikeExpressionLexer(CharStreams.fromString(str));
            final CommonTokenStream tokenStream = new CommonTokenStream(lexer);
            final JsLikeExpressionParser parser = new JsLikeExpressionParser(tokenStream);


            final TemplateStringEvaluatorVisitor visitor = new TemplateStringEvaluatorVisitor(environment);

            ret.append(parser.expression().accept(visitor).toString());
        } else {
            ret.append(str);
        }

        isInsideExpr = !isInsideExpr;
    }

    return ret.toString();
}
 
开发者ID:adamkewley,项目名称:jobson,代码行数:30,代码来源:TemplateStringEvaluator.java

示例12: ExcFile

import java.util.Scanner; //导入方法依赖的package包/类
public ExcFile(File f) throws IOException
{
    srgMethodName2ExcData = new HashMap<String, ExcData>();
    srgParamName2ExcData = new HashMap<String, ExcData>();
    // example lines:
    // net/minecraft/util/ChunkCoordinates=CL_00001555
    // net/minecraft/world/chunk/storage/AnvilChunkLoader.func_75816_a(Lnet/minecraft/world/World;Lnet/minecraft/world/chunk/Chunk;)V=net/minecraft/world/MinecraftException,java/io/IOException|p_75816_1_,p_75816_2_
    // net/minecraft/world/biome/BiomeGenMutated.func_150571_c(III)I=|p_150571_1_,p_150571_2_,p_150571_3_
    // net/minecraft/world/chunk/storage/AnvilChunkLoader.func_75818_b()V=|
    // net/minecraft/server/MinecraftServer.func_145747_a(Lnet/minecraft/util/IChatComponent;)V=|p_145747_1_

    Scanner in = new Scanner(new FileReader(f));
    try
    {
        while (in.hasNextLine())
        {
            if (in.hasNext("#"))
            {
                in.nextLine();
                continue;
            }

            in.useDelimiter("\\.");
            String srgOwner = in.next();
            in.useDelimiter("\\(");

            if (!in.hasNext())
                if (in.hasNextLine())
                    in.nextLine();
                else
                    break;

            String srgName = in.next().substring(1);
            in.useDelimiter("=");
            String descriptor = in.next();
            in.useDelimiter("\\|");
            String excs = in.next().substring(1);
            String params = in.nextLine().substring(1);

            ExcData toAdd = new ExcData(srgOwner, srgName, descriptor,
                    (excs.length() > 0 ? excs.split(",") : new String[0]),
                    (params.length() > 0 ? params.split(",") : new String[0]));

            ExcData existing = srgMethodName2ExcData.get(srgName);

            if ((existing == null) || (existing.getParameters().length < toAdd.getParameters().length))
            {
                srgMethodName2ExcData.put(srgName, toAdd);

                for (String parameter : toAdd.getParameters())
                    srgParamName2ExcData.put(parameter, toAdd);
            }
        }
    }
    finally
    {
        in.close();
    }
}
 
开发者ID:fr1kin,项目名称:ForgeHax,代码行数:60,代码来源:ExcFile.java

示例13: getResponseFromHttpUrl

import java.util.Scanner; //导入方法依赖的package包/类
@Nullable
public static String getResponseFromHttpUrl(URL url, Context context) throws IOException {
    if (updateConnectionState(context)) {

        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
        try {
            InputStream in = urlConnection.getInputStream();

            Scanner scanner = new Scanner(in);
            scanner.useDelimiter("\\A");

            boolean hasInput = scanner.hasNext();
            if (hasInput) {
                return scanner.next();
            } else {
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        } finally {
            urlConnection.disconnect();
        }
    } else {
        return null;
    }
}
 
开发者ID:secompufscar,项目名称:app_secompufscar,代码行数:28,代码来源:NetworkUtils.java


注:本文中的java.util.Scanner.useDelimiter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。