Example usage for com.google.common.io CharStreams readLines

List of usage examples for com.google.common.io CharStreams readLines

Introduction

In this page you can find the example usage for com.google.common.io CharStreams readLines.

Prototype

public static List<String> readLines(Readable r) throws IOException 

Source Link

Document

Reads all of the lines from a Readable object.

Usage

From source file:br.com.objectos.way.ssh.ChannelReader.java

public List<String> readLines() throws IOException {
    return CharStreams.readLines(reader);
}

From source file:util.mybatis.comment.PackageCommentGenerator.java

@Override
public void addJavaFileComment(CompilationUnit compilationUnit) {
    String packageComment = CodetemplatesLoader.getInstance().get("filecomment_context");
    try {/*  w  w w  . j a v  a2s  .c o m*/
        List<String> lines = CharStreams.readLines(CharStreams.newReaderSupplier(packageComment));
        if (lines == null) {
            return;
        }
        boolean isfirst = true;
        for (String line : lines) {
            line = line.trim();
            if (Strings.isNullOrEmpty(line)) {
                continue;
            }
            if (!isfirst) {
                line = " " + line;
            }
            compilationUnit.addFileCommentLine(line);
            isfirst = false;
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:google.registry.tools.CanonicalizeLabelsCommand.java

@Override
public void run() throws IOException {
    Set<String> labels = new TreeSet<>();
    for (String label : mainParameters.isEmpty() ? CharStreams.readLines(new InputStreamReader(stdin))
            : Files.readLines(new File(mainParameters.get(0)), UTF_8)) {
        label = label.trim();//w  ww  .j  a va  2s . c  o  m
        if (label.startsWith("-")) {
            label = label.substring(1);
        }
        if (label.endsWith("-")) {
            label = label.substring(0, label.length() - 1);
        }
        String canonical = canonicalize(label);
        if (canonical.startsWith(DomainNameUtils.ACE_PREFIX) && Idn.toUnicode(canonical).equals(canonical)) {
            System.err.println("Bad IDN: " + label);
            continue; // Bad IDN code points.
        }
        labels.add(canonical);
        if (!canonical.startsWith("xn--")) {
            // Using both "" and "-" to canonicalize labels.
            labels.add(canonicalize(label.replaceAll(" ", "")));
            labels.add(canonicalize(label.replaceAll(" ", "-")));
            labels.add(canonicalize(label.replaceAll("_", "")));
            labels.add(canonicalize(label.replaceAll("_", "-")));
        }
    }
    labels.remove(""); // We used "" for invalid labels.
    System.out.println(Joiner.on('\n').join(labels));
}

From source file:br.com.objectos.way.ssh.ChannelReader.java

void close() {
    try {//from w w w  .ja  va2  s  . c  o  m
        List<String> lines = CharStreams.readLines(reader);
        stdout.addAll(lines);
    } catch (IOException e) {
        exceptions.add(e);
    }

    try {
        reader.close();
    } catch (IOException e) {
        exceptions.add(e);
    }
}

From source file:com.cloudera.oryx.kmeans.serving.web.AddServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {

    KMeansGenerationManager generationManager = getGenerationManager();
    Generation generation = generationManager.getCurrentGeneration();
    if (generation == null) {
        response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE,
                "API method unavailable until model has been built and loaded");
        return;/*  ww w  .j  ava2 s  .c o  m*/
    }

    for (CharSequence line : CharStreams.readLines(request.getReader())) {
        generationManager.append(line);

        RealVector vec = generation.toVector(DelimitedDataUtils.decode(line));
        if (vec == null) {
            response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Wrong column count");
            return;
        }

        // TODO update the centers, along the lines of Meyerson et al.
    }

}

From source file:com.example.appengine.pusher.SendMessageServlet.java

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
    // Parse POST request body received in the format :
    // [{"message": "my-message", "socket_id": "1232.24", "channel": "presence-my-channel"}]

    String body = CharStreams.readLines(request.getReader()).toString();
    String json = body.replaceFirst("^\\[", "").replaceFirst("\\]$", "");
    Map<String, String> data = gson.fromJson(json, typeReference.getType());
    String message = data.get("message");
    String socketId = data.get("socket_id");
    String channelId = data.get("channel_id");

    User user = UserServiceFactory.getUserService().getCurrentUser();
    // user email prefix as display name for current logged in user
    String displayName = user.getNickname().replaceFirst("@.*", "");

    // Create a message including the user email prefix to display in the chat window
    String taggedMessage = "<strong>&lt;" + displayName + "&gt;</strong> " + message;
    Map<String, String> messageData = new HashMap<>();
    messageData.put("message", taggedMessage);

    // Send a message over the Pusher channel (maximum size of a message is 10KB)
    Result result = PusherService.getDefaultInstance().trigger(channelId, "new_message", // name of event
            messageData, socketId); // (optional) use client socket_id to exclude the sender from receiving the message

    // result.getStatus() == SUCCESS indicates successful transmission
    messageData.put("status", result.getStatus().name());

    response.getWriter().println(gson.toJson(messageData));
}

From source file:io.macgyver.cli.CLI.java

public static List<String> findPackageNamesToSearch() throws IOException {

    List<String> packageList = Lists.newArrayList();

    // packageList.add(DEFAULT_PACKAGE);
    // packageList.add(EXTENSION_PACKAGE);

    Enumeration<URL> list = Thread.currentThread().getContextClassLoader()
            .getResources("META-INF/macgyver-cli-packages");
    while (list.hasMoreElements()) {
        URL url = list.nextElement();

        try (BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()))) {
            List<String> packages = CharStreams.readLines(br);

            for (String pname : packages) {
                pname = pname.trim();//from w ww  .ja  v a  2 s  . c om
                if (!packageList.contains(pname) && !Strings.isNullOrEmpty(pname)) {
                    LoggerFactory.getLogger(CLI.class).info("Adding {} to CLI command search path", pname);
                    packageList.add(pname);
                }
            }

        }

    }
    return packageList;

}

From source file:util.mybatis.comment.ClassCommentPlugin.java

/**
 * ?./*w  w w  .  jav  a  2 s .  c  o m*/
 *
 * @param introspectedTable the introspected table
 * @param interfaze the interfaze
 */
public void classGenerated(IntrospectedTable introspectedTable, Interface interfaze) {

    Map<String, Object> local = Maps.newLinkedHashMap();
    local.put("todo", new ClassWrapper(introspectedTable));
    local.put("tags", "");

    String classComment = CodetemplatesLoader.getInstance().get("typecomment_context");
    classComment = VelocityUtils.evaluate(classComment, local);
    try {
        List<String> lines = CharStreams.readLines(CharStreams.newReaderSupplier(classComment));
        if (lines == null) {
            return;
        }
        boolean isfirst = true;
        for (String line : lines) {
            line = line.trim();
            if (Strings.isNullOrEmpty(line)) {
                continue;
            }
            if (!isfirst) {
                line = " " + line;
            }
            interfaze.addJavaDocLine(line);
            isfirst = false;
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.tasktop.koans.PathToEnlightment.java

private List<String> getEnlightment() {
    try (InputStream in = PathToEnlightment.class.getResourceAsStream("/enlightment.txt")) {
        List<String> lines = CharStreams.readLines(new InputStreamReader(in, Charsets.UTF_8));
        return lines.stream().map(line -> color(CYAN, line)).collect(Collectors.toList());
    } catch (IOException shouldnotHappen) {
        throw new IllegalStateException(shouldnotHappen);
    }/* w  w  w.j  a  va2  s  .c  o m*/
}

From source file:com.dmdirc.addons.dcc.kde.KDialogProcess.java

/**
 * Execute kdialog with the Parameters in params.
 *
 * @param params Parameters to pass to kdialog
 *
 * @throws IOException if an I/O error occurs
 *///from  ww w.  ja  va2 s .  com
public KDialogProcess(final String[] params) throws IOException {
    final String[] exec = new String[params.length + 1];
    System.arraycopy(params, 0, exec, 1, params.length);
    exec[0] = IS_BIN ? "/bin/kdialog" : "/usr/bin/kdialog";
    process = Runtime.getRuntime().exec(exec);
    stdOutput = CharStreams.readLines(new InputStreamReader(process.getInputStream()));
    stdError = CharStreams.readLines(new InputStreamReader(process.getErrorStream()));
}