Example usage for com.google.common.collect Iterables toArray

List of usage examples for com.google.common.collect Iterables toArray

Introduction

In this page you can find the example usage for com.google.common.collect Iterables toArray.

Prototype

static <T> T[] toArray(Iterable<? extends T> iterable, T[] array) 

Source Link

Usage

From source file:ezbakehelpers.ezconfigurationhelpers.ssl.SslConfigurationHelper.java

/**
 * Get the configured SSL Ciphers, if set. Will return null if the key has no value.
 *
 * @return an array of ciphers, or null if no value was set
 *///from   w w  w.  ja v a  2s .  c o m
public String[] getSslCiphers() {
    String ciphers = ezProperties.getProperty(EzBakePropertyConstants.EZBAKE_SSL_CIPHERS_KEY);
    if (ciphers != null) {
        return Iterables.toArray(Splitter.on(',').trimResults().omitEmptyStrings().split(ciphers),
                String.class);
    }
    return null;
}

From source file:eu.numberfour.n4js.ui.workingsets.WorkingSetManagerImpl.java

@Override
public WorkingSet[] getAllWorkingSets() {
    return Iterables.toArray(getOrCreateAllWorkingSets(), WorkingSet.class);
}

From source file:com.comphenix.protocol.events.PacketAdapter.java

/**
 * Initialize a packet listener with the given parameters.
 * @param plugin - the plugin./* ww  w.j a va 2  s.c  o  m*/
 * @param listenerPriority - the priority.
 * @param types - the packet types.
 */
public PacketAdapter(Plugin plugin, ListenerPriority listenerPriority, Iterable<? extends PacketType> types) {
    this(params(plugin, Iterables.toArray(types, PacketType.class)).listenerPriority(listenerPriority));
}

From source file:com.zulily.omicron.alert.EmailSender.java

public void send(final String subject, final String message) throws MessagingException {
    checkArgument(!Strings.isNullOrEmpty(subject), "Cannot send email with a null or empty subject");
    checkArgument(!Strings.isNullOrEmpty(message), "Cannot send email with a null or empty message");

    if (EXAMPLE_ADDRESS.equalsIgnoreCase(from.toString())) {
        dumpEmail(subject, message);/*from ww w  .  j  a v a 2 s .  c o m*/
        // Allow testing to use a fake address
        return;
    }

    MimeMessage mimeMessage = new MimeMessage(this.smtpSession);
    mimeMessage.setRecipients(Message.RecipientType.TO, Iterables.toArray(recipients, Address.class));
    mimeMessage.setFrom(this.from);
    mimeMessage.setSubject(subject);
    mimeMessage.setContent(message, "text/plain");
    Transport.send(mimeMessage);

}

From source file:org.apache.abdera2.common.io.Compression.java

/**
 * Wrap an InputStream of compressed data so it can be automatically
 * decompressed as it is read. If multiple compression codecs have
 * been applied, they will be layered accordingly
 *///from w  w w .j  a va  2  s . c om
public static InputStream wrap(InputStream in, Iterable<CompressionCodec> codecs) throws IOException {
    return wrap(in, Iterables.toArray(codecs, CompressionCodec.class));
}

From source file:org.apache.abdera2.security.xmlsec.XmlSignature.java

@SuppressWarnings("unchecked")
private <T extends Element> T _sign(T element, SignatureOptions options) throws XMLSecurityException {
    element.setBaseUri(element.getResolvedBaseUri());
    org.w3c.dom.Element dom = fomToDom((Element) element.clone(), options);
    org.w3c.dom.Document domdoc = dom.getOwnerDocument();
    PrivateKey signingKey = options.getSigningKey();
    X509Certificate cert = options.getCertificate();
    PublicKey pkey = options.getPublicKey();
    IRI baseUri = element.getResolvedBaseUri();
    XMLSignature sig = new XMLSignature(domdoc, (baseUri != null) ? baseUri.toString() : "",
            options.getSigningAlgorithm());
    dom.appendChild(sig.getElement());//from   w  w w  .j a  v  a 2s  . co  m
    Transforms transforms = new Transforms(domdoc);
    transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
    transforms.addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
    sig.addDocument("", transforms, org.apache.xml.security.utils.Constants.ALGO_ID_DIGEST_SHA1);
    for (String ref : options.getReferences())
        sig.addDocument(ref);

    if (options.isSignLinks()) {
        String[] rels = Iterables.toArray(options.getSignLinkRels(), String.class);
        List<Link> links = null;
        Content content = null;
        if (element instanceof Source) {
            links = (rels == null) ? ((Source) element).getLinks() : ((Source) element).getLinks(rels);
        } else if (element instanceof Entry) {
            links = (rels == null) ? ((Entry) element).getLinks() : ((Entry) element).getLinks(rels);
            content = ((Entry) element).getContentElement();
        }
        if (links != null) {
            for (Link link : links) {
                sig.addDocument(link.getResolvedHref().toASCIIString());
            }
        }
        if (content != null && content.getResolvedSrc() != null)
            sig.addDocument(content.getResolvedSrc().toASCIIString());
    }

    if (cert != null)
        sig.addKeyInfo(cert);
    if (pkey != null)
        sig.addKeyInfo(pkey);
    sig.sign(signingKey);
    return (T) domToFom(dom, options);
}

From source file:net.minecraftforge.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper.java

public void setupLoadOnly(String deobfFileName, boolean loadAll) {
    try {//from  w  w  w .  j a  v a2 s  .co m
        File mapData = new File(deobfFileName);
        LZMAInputSupplier zis = new LZMAInputSupplier(new FileInputStream(mapData));
        CharSource srgSource = zis.asCharSource(Charsets.UTF_8);
        List<String> srgList = srgSource.readLines();
        rawMethodMaps = Maps.newHashMap();
        rawFieldMaps = Maps.newHashMap();
        Builder<String, String> builder = ImmutableBiMap.<String, String>builder();
        Splitter splitter = Splitter.on(CharMatcher.anyOf(": ")).omitEmptyStrings().trimResults();
        for (String line : srgList) {
            String[] parts = Iterables.toArray(splitter.split(line), String.class);
            String typ = parts[0];
            if ("CL".equals(typ)) {
                parseClass(builder, parts);
            } else if ("MD".equals(typ) && loadAll) {
                parseMethod(parts);
            } else if ("FD".equals(typ) && loadAll) {
                parseField(parts);
            }
        }
        classNameBiMap = builder.build();
    } catch (IOException ioe) {
        FMLRelaunchLog.log(Level.ERROR, "An error occurred loading the deobfuscation map data", ioe);
    }
    methodNameMaps = Maps.newHashMapWithExpectedSize(rawMethodMaps.size());
    fieldNameMaps = Maps.newHashMapWithExpectedSize(rawFieldMaps.size());

}

From source file:org.obm.push.cassandra.CassandraSessionSupplierImpl.java

@Inject
@VisibleForTesting/* www.  java 2s.  c  o m*/
CassandraSessionSupplierImpl(final CassandraConfiguration cassandraConfiguration,
        @Named(LoggerModule.CONFIGURATION) final Logger configurationLogger) {

    configurationLogger.info("CASSANDRA SEEDS are {}", cassandraConfiguration.seeds());
    configurationLogger.info("CASSANDRA USER is {}", cassandraConfiguration.user());
    configurationLogger.info("CASSANDRA KEYSPACE is {}", cassandraConfiguration.keyspace());
    configurationLogger.debug("CASSANDRA CLIENT READ TIMEOUT is {}", cassandraConfiguration.readTimeoutMs());
    sessionSupplier = Suppliers.memoize(new Supplier<Session>() {

        @Override
        public Session get() {
            try {
                hasBeenSupplied = true;
                return Cluster.builder()
                        .addContactPoints(Iterables.toArray(cassandraConfiguration.seeds(), String.class))
                        .withCredentials(cassandraConfiguration.user(), cassandraConfiguration.password())
                        .withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.QUORUM))
                        .withSocketOptions(new SocketOptions()
                                .setReadTimeoutMillis(cassandraConfiguration.readTimeoutMs()))
                        .withRetryPolicy(retryPolicy(cassandraConfiguration)).build()
                        .connect(cassandraConfiguration.keyspace());
            } catch (NoHostAvailableException e) {
                configurationLogger.error("Cannot establish Cassandra connection: {}", e.getMessage());
                throw e;
            }
        }
    });
}

From source file:cpw.mods.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper.java

public void setupLoadOnly(String deobfFileName, boolean loadAll) {
    try {/*from   w ww.  java2s. c  o  m*/
        File mapData = new File(deobfFileName);
        LZMAInputSupplier zis = new LZMAInputSupplier(new FileInputStream(mapData));
        InputSupplier<InputStreamReader> srgSupplier = CharStreams.newReaderSupplier(zis, Charsets.UTF_8);
        List<String> srgList = CharStreams.readLines(srgSupplier);
        rawMethodMaps = Maps.newHashMap();
        rawFieldMaps = Maps.newHashMap();
        Builder<String, String> builder = ImmutableBiMap.<String, String>builder();
        Splitter splitter = Splitter.on(CharMatcher.anyOf(": ")).omitEmptyStrings().trimResults();
        for (String line : srgList) {
            String[] parts = Iterables.toArray(splitter.split(line), String.class);
            String typ = parts[0];
            if ("CL".equals(typ)) {
                parseClass(builder, parts);
            } else if ("MD".equals(typ) && loadAll) {
                parseMethod(parts);
            } else if ("FD".equals(typ) && loadAll) {
                parseField(parts);
            }
        }
        classNameBiMap = builder.build();
    } catch (IOException ioe) {
        FMLRelaunchLog.log(Level.ERROR, "An error occurred loading the deobfuscation map data", ioe);
    }
    methodNameMaps = Maps.newHashMapWithExpectedSize(rawMethodMaps.size());
    fieldNameMaps = Maps.newHashMapWithExpectedSize(rawFieldMaps.size());

}

From source file:org.summer.ss.ide.hyperlinking.SsHyperlinkHelper.java

/**
 * If multiple links are requested, all ambiguous candidates are provided for feature
 * and constructor calls. /*from  ww  w.  java2s.  c  om*/
 */
@Override
public IHyperlink[] createHyperlinksByOffset(XtextResource resource, int offset,
        boolean createMultipleHyperlinks) {
    if (!createMultipleHyperlinks) {
        return super.createHyperlinksByOffset(resource, offset, createMultipleHyperlinks);
    }
    List<IHyperlink> links = Lists.newArrayList();
    IHyperlinkAcceptor acceptor = new HyperlinkAcceptor(links);

    createMultipleHyperlinksByOffset(resource, offset, acceptor);
    if (!links.isEmpty())
        return Iterables.toArray(links, IHyperlink.class);
    return null;
}