Example usage for com.google.common.base CharMatcher BREAKING_WHITESPACE

List of usage examples for com.google.common.base CharMatcher BREAKING_WHITESPACE

Introduction

In this page you can find the example usage for com.google.common.base CharMatcher BREAKING_WHITESPACE.

Prototype

CharMatcher BREAKING_WHITESPACE

To view the source code for com.google.common.base CharMatcher BREAKING_WHITESPACE.

Click Source Link

Document

Determines whether a character is a breaking whitespace (that is, a whitespace which can be interpreted as a break between words for formatting purposes).

Usage

From source file:com.google.cloud.genomics.dataflow.pipelines.DeleteVariants.java

public static void main(String[] args) throws IOException, GeneralSecurityException {
    // Register the options so that they show up via --help
    PipelineOptionsFactory.register(Options.class);
    Options options = PipelineOptionsFactory.fromArgs(args).withValidation().as(Options.class);
    // Option validation is not yet automatic, we make an explicit call here.
    Options.Methods.validateOptions(options);

    OfflineAuth auth = GenomicsOptions.Methods.getGenomicsAuth(options);

    GenomicsOptions.Methods.requestConfirmation("*** The pipeline will delete variants whose "
            + "ids are listed in: " + options.getInput() + ". ***");

    Pipeline p = Pipeline.create(options);

    p.apply(TextIO.Read.named("ReadLines").from(options.getInput()))
            .apply(ParDo.named("ParseVariantIds").of(new DoFn<String, String>() {
                @Override//from w  ww .j av  a  2s.c  om
                public void processElement(ProcessContext c) {
                    String record = c.element();

                    // The variant id will be retrieved from the first column.  Any other columns
                    // will be ignored.
                    Iterable<String> fields = Splitter
                            .on(CharMatcher.BREAKING_WHITESPACE.or(CharMatcher.is(','))).omitEmptyStrings()
                            .trimResults().split(record);
                    java.util.Iterator<String> iter = fields.iterator();
                    if (iter.hasNext()) {
                        c.output(iter.next());
                    }
                }
            })).apply(ParDo.of(new DeleteVariantFn(auth))).apply(Sum.integersGlobally())
            .apply(ParDo.named("FormatResults").of(new DoFn<Integer, String>() {
                @Override
                public void processElement(ProcessContext c) {
                    c.output("Deleted Variant Count: " + c.element());
                }
            })).apply(TextIO.Write.named("Write Count").to(options.getOutput()));

    p.run();
}

From source file:com.google.cloud.genomics.dataflow.pipelines.IdentifyPrivateVariants.java

public static void main(String[] args) throws IOException, GeneralSecurityException {
    // Register the options so that they show up via --help
    PipelineOptionsFactory.register(Options.class);
    Options options = PipelineOptionsFactory.fromArgs(args).withValidation().as(Options.class);
    // Option validation is not yet automatic, we make an explicit call here.
    Options.Methods.validateOptions(options);

    OfflineAuth auth = GenomicsOptions.Methods.getGenomicsAuth(options);

    // Grab and parse the list of callset IDs.
    String fileContents = Files.toString(new File(options.getCallSetIdsFilepath()), Charset.defaultCharset());
    ImmutableSet<String> callSetIds = ImmutableSet.<String>builder().addAll(
            Splitter.on(CharMatcher.BREAKING_WHITESPACE).omitEmptyStrings().trimResults().split(fileContents))
            .build();/*w w  w . j  a v  a  2 s. c om*/
    LOG.info("The pipeline will identify and write to Cloud Storage variants " + "private to "
            + callSetIds.size() + " genomes with callSetIds: " + callSetIds);
    if (options.getIdentifyVariantsWithoutCalls()) {
        LOG.info("* The pipeline will also identify variants with no callsets. *");
    }

    List<StreamVariantsRequest> shardRequests = options.isAllReferences()
            ? ShardUtils.getVariantRequests(options.getVariantSetId(),
                    ShardUtils.SexChromosomeFilter.INCLUDE_XY, options.getBasesPerShard(), auth)
            : ShardUtils.getVariantRequests(options.getVariantSetId(), options.getReferences(),
                    options.getBasesPerShard());

    Pipeline p = Pipeline.create(options);
    PCollection<Variant> variants = p.begin().apply(Create.of(shardRequests))
            .apply(new VariantStreamer(auth, ShardBoundary.Requirement.STRICT, VARIANT_FIELDS)).apply(ParDo
                    .of(new PrivateVariantsFilterFn(callSetIds, options.getIdentifyVariantsWithoutCalls())));

    variants.apply(ParDo.named("FormatResults").of(new DoFn<Variant, String>() {
        @Override
        public void processElement(ProcessContext c) {
            Variant v = c.element();
            c.output(Joiner.on("\t").join(v.getId(), v.getReferenceName(), v.getStart(), v.getEnd(),
                    v.getReferenceBases(), Joiner.on(",").join(v.getAlternateBasesList())));
        }
    })).apply(TextIO.Write.to(options.getOutput()));

    p.run();
}

From source file:org.anarres.dblx.core.model.ModelLoader.java

@Nonnull
public Model load() throws IOException {
    Model model = new Model(modelName);

    Splitter splitter = Splitter.on(CharMatcher.BREAKING_WHITESPACE);

    NODES: {//from  w  w w . j av  a  2s  .  c om
        URL url = Resources.getResource("models/" + modelName + "/nodes.csv");
        CharSource source = Resources.asCharSource(url, StandardCharsets.UTF_8);
        try (Reader in = source.openBufferedStream()) {
            CSVReader reader = newSVReader(in, '\t', 1);
            for (String[] line : reader) {
                String name = line[0];
                long x = (long) LengthUnit.INCH.toMillimetres(Double.parseDouble(line[1]));
                long y = (long) LengthUnit.INCH.toMillimetres(Double.parseDouble(line[2]));
                long z = (long) LengthUnit.INCH.toMillimetres(Double.parseDouble(line[3]));
                List<String> tags = splitter.splitToList(line[4]);
                model.addNode(new Node(name, x, y, z, tags));
            }
        }
    }

    BARS: {
        URL url = Resources.getResource("models/" + modelName + "/bars.csv");
        CharSource source = Resources.asCharSource(url, StandardCharsets.UTF_8);
        try (Reader in = source.openBufferedStream()) {
            CSVReader reader = newSVReader(in, '\t', 1);
            for (String[] line : reader) {
                List<String> tags = splitter.splitToList(line[2]);
                Bar bar = new Bar(line[0], line[1], tags);
                model.addEdge(bar);
            }
        }
    }

    return model;
}

From source file:org.graylog2.shared.security.tls.PemReader.java

static List<byte[]> readCertificates(Path path) throws CertificateException {
    final byte[] bytes;
    try {//from  w w w.  j a  v a  2  s  .co  m
        bytes = Files.readAllBytes(path);
    } catch (IOException e) {
        throw new CertificateException("Couldn't read certificates from file: " + path, e);
    }

    final String content = new String(bytes, StandardCharsets.US_ASCII);
    final Matcher m = CERT_PATTERN.matcher(content);

    final List<byte[]> certs = new ArrayList<>();
    int start = 0;
    while (m.find(start)) {
        final String s = m.group(1);
        byte[] der = Base64.getDecoder().decode(CharMatcher.BREAKING_WHITESPACE.removeFrom(s));
        certs.add(der);

        start = m.end();
    }

    if (certs.isEmpty()) {
        throw new CertificateException("No certificates found in file: " + path);
    }

    return certs;
}

From source file:org.onehippo.cms7.essentials.components.utils.ComponentsUtils.java

/**
 * Get a string List from comma-separated values of a configuration parameter.
 *//*www  . ja va  2s  .  c  om*/
public static List<String> getParameterList(final BaseHstComponent comp, final HstRequest request,
        final String paramName) {

    String commaSepValues = comp.getComponentParameter(paramName);

    if (commaSepValues == null) {
        return Collections.emptyList();
    }

    final Iterable<String> iterable = Splitter.on(',').omitEmptyStrings().trimResults().split(commaSepValues);
    List<String> list = new ArrayList<>();
    for (String value : iterable) {
        list.add(CharMatcher.BREAKING_WHITESPACE.trimFrom(value));
    }
    return list;
}

From source file:org.aliuge.crawler.extractor.selector.action.string.StringFilterAction.java

/**
 * /* w  ww.  j a  v a 2s. com*/
 */
@Override
public String doAction(String content) {
    for (CharType ct : set) {
        switch (ct) {
        case INVISIBLE:
            content = CharMatcher.INVISIBLE.removeFrom(content);

        case BREAKING_WHITESPACE:
            content = CharMatcher.BREAKING_WHITESPACE.removeFrom(content);
        case DIGIT:
            content = CharMatcher.DIGIT.removeFrom(content);
        case LETTER:
            content = CharMatcher.JAVA_LETTER.removeFrom(content);
        default:
            break;
        }
    }
    if (StringUtils.isNotBlank(filterString)) {
        content = CharMatcher.anyOf(filterString).removeFrom(content);
    }
    return content;
}

From source file:org.graylog2.shared.security.tls.PemReader.java

static byte[] readPrivateKey(Path path) throws KeyException {
    final byte[] bytes;
    try {/*  w  w w .java  2  s  .  c o m*/
        bytes = Files.readAllBytes(path);
    } catch (IOException e) {
        throw new KeyException("Couldn't read private key from file: " + path, e);
    }

    final String content = new String(bytes, StandardCharsets.US_ASCII);
    final Matcher m = KEY_PATTERN.matcher(content);
    if (!m.find()) {
        throw new KeyException("No private key found in file: " + path);
    }

    final String s = CharMatcher.BREAKING_WHITESPACE.removeFrom(m.group(1));
    byte[] base64 = s.getBytes(StandardCharsets.US_ASCII);
    return Base64.getDecoder().decode(base64);
}

From source file:com.google.cloud.genomics.examples.TransformNonVariantSegmentData.java

public static void main(String[] args) throws IOException, GeneralSecurityException {
    // Register the options so that they show up via --help.
    PipelineOptionsFactory.register(TransformNonVariantSegmentData.Options.class);
    TransformNonVariantSegmentData.Options options = PipelineOptionsFactory.fromArgs(args).withValidation()
            .as(TransformNonVariantSegmentData.Options.class);

    // Option validation is not yet automatic, we make an explicit call here.
    GenomicsDatasetOptions.Methods.validateOptions(options);
    Preconditions.checkState(options.getHasNonVariantSegments(),
            "This job is only valid for data containing non-variant segments. "
                    + "Set the --hasNonVariantSegments command line option accordingly.");

    // Grab and parse our optional list of genomes to skip.
    ImmutableSet<String> callSetNamesToExclude = null;
    String skipFilepath = options.getCallSetNamesToExclude();
    if (null != skipFilepath) {
        Iterable<String> callSetNames = Splitter.on(CharMatcher.BREAKING_WHITESPACE).omitEmptyStrings()
                .trimResults().split(Files.toString(new File(skipFilepath), Charset.defaultCharset()));
        callSetNamesToExclude = ImmutableSet.<String>builder().addAll(callSetNames).build();
        LOG.info("The pipeline will skip " + callSetNamesToExclude.size() + " genomes with callSetNames: "
                + callSetNamesToExclude);
    }//from  ww  w  .  ja  va 2 s.  c  om

    GenomicsFactory.OfflineAuth auth = GenomicsOptions.Methods.getGenomicsAuth(options);
    List<SearchVariantsRequest> requests = GenomicsDatasetOptions.Methods.getVariantRequests(options, auth,
            SexChromosomeFilter.INCLUDE_XY);

    Pipeline p = Pipeline.create(options);
    DataflowWorkarounds.registerGenomicsCoders(p);

    PCollection<SearchVariantsRequest> input = p.begin().apply(Create.of(requests));

    // Create a collection of data with non-variant segments omitted but calls from overlapping
    // non-variant segments added to SNPs.
    PCollection<Variant> variants = JoinNonVariantSegmentsWithVariants.joinVariantsTransform(input, auth);

    // For each variant flag whether or not it has ambiguous calls for a particular sample and
    // optionally filter calls.
    PCollection<Variant> flaggedVariants = callSetNamesToExclude == null
            ? variants.apply(ParDo.of(new FlagVariantsWithAmbiguousCallsFn()))
            : variants.apply(ParDo.of(new FilterCallsFn(callSetNamesToExclude)))
                    .apply(ParDo.of(new FlagVariantsWithAmbiguousCallsFn()));

    // Emit the variants to BigQuery.
    flaggedVariants.apply(ParDo.of(new FormatVariantsFn()))
            .apply(BigQueryIO.Write.to(options.getOutputTable()).withSchema(getTableSchema())
                    .withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED)
                    .withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_TRUNCATE));

    p.run();
}

From source file:com.bennavetta.aeneas.mesos.slave.docker.Daemon.java

private static void mountFilesystems() throws IOException {
    Path cgroup = Paths.get("/sys/fs/cgroup");
    if (!Files.isDirectory(cgroup))
        Files.createDirectory(cgroup);

    LOG.debug("Creating '{}' tmpfs", cgroup);
    if (!isMountpoint(cgroup)) {
        try {//w  ww.  j  av a  2  s  .co m
            mount(cgroup, "cgroup", "tmpfs", "uid=0,gid=0,mode=0755", false);
        } catch (IOException e) {
            throw new IOException("Could not make a tmpfs mount. Was the --privileged flag used?", e);
        }
    }

    Path security = Paths.get("/sys/kernel/security");
    LOG.debug("Creating security file system in '{}'", security);
    if (Files.isDirectory(security) && !isMountpoint(security)) {
        try {
            mount(security, "none", "securityfs", null, true);
        } catch (IOException e) {
            LOG.warn("Could not mount {}. AppArmor detection and --privileged mode might break.", security);
        }
    }

    String cgroupsText = new String(Files.readAllBytes(Paths.get("/proc/1/cgroup")));
    List<String> cgroups = StreamSupport.stream(Splitter.on('\n').split(cgroupsText).spliterator(), false)
            .filter(s -> !s.trim().isEmpty()).map(s -> Splitter.on(':').split(s)).map(i -> Iterables.get(i, 1))
            .collect(Collectors.toList());
    for (String subsystem : cgroups) {
        LOG.debug("Creating '{}' cgroup", subsystem);
        Path subsysPath = cgroup.resolve(subsystem);
        if (!Files.isDirectory(subsysPath))
            Files.createDirectory(subsysPath);
        if (!isMountpoint(subsysPath)) {
            mount(subsysPath, "cgroup", "cgroup", subsystem, false);
        }

        /*
         * Address some bugs
         * See https://github.com/jpetazzo/dind/blob/master/wrapdocker
          */
        if (subsystem.startsWith("name=")) {
            String name = subsystem.substring(6);
            Files.createSymbolicLink(cgroup.resolve(name), Paths.get(subsystem));
        }

        if (subsystem.equals("cpuacct,cpu")) {
            Files.createSymbolicLink(cgroup.resolve("cpu,cpuacct"), Paths.get(subsystem));
        }
    }

    if (!cgroupsText.contains(":devices:")) {
        LOG.warn("The 'devices' cgroup should be in its own hierarchy.");
    }

    if (!Iterables.contains(Splitter.on(CharMatcher.BREAKING_WHITESPACE).split(cgroupsText), "devices")) {
        LOG.warn("The 'devices' cgroup does not appear to be mounted.");
    }
}

From source file:com.splout.db.qnode.rest.DeployRollbackServlet.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    StringBuffer postBody = new StringBuffer();
    String line = null;/*from w  ww .j  a v  a  2  s  .c o  m*/

    BufferedReader reader = req.getReader();
    while ((line = reader.readLine()) != null) {
        postBody.append(line);
    }

    resp.setHeader("content-type", "application/json;charset=UTF-8");
    resp.setCharacterEncoding("UTF-8");

    String action = req.getParameter("action");
    String response = null;

    try {
        if (action.equals(ACTION_DEPLOY)) {
            List<DeployRequest> deployReq = JSONSerDe.deSer(postBody.toString(), DEPLOY_REQ_REF);

            // List of DeployRequest
            log.info(Thread.currentThread().getName() + ": Deploy request received ["
                    + CharMatcher.BREAKING_WHITESPACE.removeFrom(postBody.toString()) + "]");
            for (DeployRequest request : deployReq) {
                if (request.getReplicationMap() == null || request.getReplicationMap().size() < 1) {
                    throw new IllegalArgumentException(
                            "Invalid deploy request with empty replication map [" + request + "]");
                }
                if (request.getPartitionMap().size() != request.getReplicationMap().size()) {
                    throw new IllegalArgumentException(
                            "Invalid deploy request with non-coherent replication / partition maps [" + request
                                    + "]");
                }
                if (request.getEngine() == null) {
                    throw new IllegalArgumentException("Invalid deploy request with null engine id received");
                }
            }
            response = JSONSerDe.ser(qNodeHandler.deploy(deployReq));
        } else if (action.equals(ACTION_ROLLBACK)) {
            ArrayList<SwitchVersionRequest> rReq = JSONSerDe.deSer(postBody.toString(), ROLLBACK_REQ_REF);
            // List of RollbackRequest
            log.info(Thread.currentThread().getName() + ": Rollback request received [" + rReq + "]");
            response = JSONSerDe.ser(qNodeHandler.rollback(rReq));
        } else {
            throw new ServletException("Unknown action: " + action);
        }

        resp.getWriter().append(response);
    } catch (Exception e) {
        log.error(e);
        throw new ServletException(e);
    }
}