List of usage examples for com.google.common.collect Iterables toArray
static <T> T[] toArray(Iterable<? extends T> iterable, T[] array)
From source file:org.apache.metron.parsers.paloalto.BasicPaloAltoFirewallParser.java
@SuppressWarnings("unchecked") private void parseMessage(String message, JSONObject outputMessage) { String[] tokens = Iterables.toArray( Splitter.on(Pattern.compile(",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)")).split(message), String.class); int parser_version = 0; String type = tokens[3].trim(); //populate common objects if (!empty_attribute(tokens[0])) outputMessage.put(PaloAltoDomain, tokens[0].trim()); if (!empty_attribute(tokens[1])) outputMessage.put(ReceiveTime, tokens[1].trim()); if (!empty_attribute(tokens[2])) outputMessage.put(SerialNum, tokens[2].trim()); outputMessage.put(Type, type); if (!empty_attribute(tokens[4])) outputMessage.put(ThreatContentType, unquoted_attribute(tokens[4])); if (!empty_attribute(tokens[5])) outputMessage.put(ConfigVersion, tokens[5].trim()); if (!empty_attribute(tokens[6])) outputMessage.put(GenerateTime, tokens[6].trim()); if (!empty_attribute(tokens[7])) outputMessage.put(SourceAddress, tokens[7].trim()); if (!empty_attribute(tokens[8])) outputMessage.put(DestinationAddress, tokens[8].trim()); if (!empty_attribute(tokens[9])) outputMessage.put(NATSourceIP, tokens[9].trim()); if (!empty_attribute(tokens[10])) outputMessage.put(NATDestinationIP, tokens[10].trim()); if (!empty_attribute(tokens[11])) outputMessage.put(Rule, unquoted_attribute(tokens[11])); if (!empty_attribute(tokens[12])) outputMessage.put(SourceUser, unquoted_attribute(tokens[12])); if (!empty_attribute(tokens[13])) outputMessage.put(DestinationUser, unquoted_attribute(tokens[13])); if (!empty_attribute(tokens[14])) outputMessage.put(Application, unquoted_attribute(tokens[14])); if (!empty_attribute(tokens[15])) outputMessage.put(VirtualSystem, unquoted_attribute(tokens[15])); if (!empty_attribute(tokens[16])) outputMessage.put(SourceZone, unquoted_attribute(tokens[16])); if (!empty_attribute(tokens[17])) outputMessage.put(DestinationZone, unquoted_attribute(tokens[17])); if (!empty_attribute(tokens[18])) outputMessage.put(InboundInterface, unquoted_attribute(tokens[18])); if (!empty_attribute(tokens[19])) outputMessage.put(OutboundInterface, unquoted_attribute(tokens[19])); if (!empty_attribute(tokens[20])) outputMessage.put(LogAction, unquoted_attribute(tokens[20])); if (!empty_attribute(tokens[21])) outputMessage.put(TimeLogged, tokens[21].trim()); if (!empty_attribute(tokens[22])) outputMessage.put(SessionID, tokens[22].trim()); if (!empty_attribute(tokens[23])) outputMessage.put(RepeatCount, tokens[23].trim()); if (!empty_attribute(tokens[24])) outputMessage.put(SourcePort, tokens[24].trim()); if (!empty_attribute(tokens[25])) outputMessage.put(DestinationPort, tokens[25].trim()); if (!empty_attribute(tokens[26])) outputMessage.put(NATSourcePort, tokens[26].trim()); if (!empty_attribute(tokens[27])) outputMessage.put(NATDestinationPort, tokens[27].trim()); if (!empty_attribute(tokens[28])) outputMessage.put(Flags, tokens[28].trim()); if (!empty_attribute(tokens[29])) outputMessage.put(IPProtocol, unquoted_attribute(tokens[29])); if (!empty_attribute(tokens[30])) outputMessage.put(Action, unquoted_attribute(tokens[30])); if ("THREAT".equals(type.toUpperCase())) { int p1_offset = 0; if (tokens.length == 45) parser_version = 60;// w w w. j a va 2s .co m else if (tokens.length == 53) parser_version = 61; else if (tokens.length == 61) { parser_version = 70; p1_offset = 1; } else if (tokens.length == 72) { parser_version = 80; p1_offset = 1; } outputMessage.put(ParserVersion, parser_version); if (!empty_attribute(tokens[31])) { outputMessage.put(URL, unquoted_attribute(tokens[31])); try { URL url = new URL(unquoted_attribute(tokens[31])); outputMessage.put(HOST, url.getHost()); } catch (MalformedURLException e) { } } if (!empty_attribute(tokens[32])) outputMessage.put(ThreatID, tokens[32].trim()); if (!empty_attribute(tokens[33])) outputMessage.put(Category, unquoted_attribute(tokens[33])); if (!empty_attribute(tokens[34])) outputMessage.put(Severity, unquoted_attribute(tokens[34])); if (!empty_attribute(tokens[35])) outputMessage.put(Direction, unquoted_attribute(tokens[35])); if (!empty_attribute(tokens[36])) outputMessage.put(Seqno, tokens[36].trim()); if (!empty_attribute(tokens[37])) outputMessage.put(ActionFlags, unquoted_attribute(tokens[37])); if (!empty_attribute(tokens[38])) outputMessage.put(SourceLocation, unquoted_attribute(tokens[38])); if (!empty_attribute(tokens[39])) outputMessage.put(DestinationLocation, unquoted_attribute(tokens[39])); if (!empty_attribute(tokens[41])) outputMessage.put(ContentType, unquoted_attribute(tokens[41])); if (!empty_attribute(tokens[42])) outputMessage.put(PCAPID, tokens[42].trim()); if (!empty_attribute(tokens[43])) outputMessage.put(WFFileDigest, unquoted_attribute(tokens[43])); if (!empty_attribute(tokens[44])) outputMessage.put(WFCloud, unquoted_attribute(tokens[44])); if (parser_version >= 61) { if (!empty_attribute(tokens[(45 + p1_offset)])) outputMessage.put(UserAgent, unquoted_attribute(tokens[(45 + p1_offset)])); if (!empty_attribute(tokens[(46 + p1_offset)])) outputMessage.put(WFFileType, unquoted_attribute(tokens[(46 + p1_offset)])); if (!empty_attribute(tokens[(47 + p1_offset)])) outputMessage.put(XForwardedFor, unquoted_attribute(tokens[(47 + p1_offset)])); if (!empty_attribute(tokens[(48 + p1_offset)])) outputMessage.put(Referer, unquoted_attribute(tokens[(48 + p1_offset)])); if (!empty_attribute(tokens[(49 + p1_offset)])) outputMessage.put(WFSender, unquoted_attribute(tokens[(49 + p1_offset)])); if (!empty_attribute(tokens[(50 + p1_offset)])) outputMessage.put(WFSubject, unquoted_attribute(tokens[(50 + p1_offset)])); if (!empty_attribute(tokens[(51 + p1_offset)])) outputMessage.put(WFRecipient, unquoted_attribute(tokens[(51 + p1_offset)])); if (!empty_attribute(tokens[(52 + p1_offset)])) outputMessage.put(WFReportID, unquoted_attribute(tokens[(52 + p1_offset)])); } if (parser_version >= 70) { if (!empty_attribute(tokens[45])) outputMessage.put(URLIndex, tokens[45].trim()); if (!empty_attribute(tokens[54])) outputMessage.put(DGH1, tokens[54].trim()); if (!empty_attribute(tokens[55])) outputMessage.put(DGH2, tokens[55].trim()); if (!empty_attribute(tokens[56])) outputMessage.put(DGH3, tokens[56].trim()); if (!empty_attribute(tokens[57])) outputMessage.put(DGH4, tokens[57].trim()); if (!empty_attribute(tokens[58])) outputMessage.put(VSYSName, unquoted_attribute(tokens[58])); if (!empty_attribute(tokens[59])) outputMessage.put(DeviceName, unquoted_attribute(tokens[59])); } if (parser_version >= 80) { if (!empty_attribute(tokens[61])) outputMessage.put(SourceVmUuid, tokens[61].trim()); if (!empty_attribute(tokens[62])) outputMessage.put(DestinationVmUuid, tokens[62].trim()); if (!empty_attribute(tokens[63])) outputMessage.put(HTTPMethod, tokens[63].trim()); if (!empty_attribute(tokens[64])) outputMessage.put(TunnelId, tokens[64].trim()); if (!empty_attribute(tokens[65])) outputMessage.put(MonitorTag, tokens[65].trim()); if (!empty_attribute(tokens[66])) outputMessage.put(ParentSessionId, tokens[66].trim()); if (!empty_attribute(tokens[67])) outputMessage.put(ParentSessionStartTime, tokens[67].trim()); if (!empty_attribute(tokens[68])) outputMessage.put(TunnelType, tokens[68].trim()); if (!empty_attribute(tokens[69])) outputMessage.put(ThreatCategory, tokens[69].trim()); if (!empty_attribute(tokens[70])) outputMessage.put(ContentVersion, tokens[70].trim()); } if (parser_version == 0) { outputMessage.put(Tokens, tokens.length); } } else if ("TRAFFIC".equals(type.toUpperCase())) { if (tokens.length == 46) parser_version = 60; else if (tokens.length == 47) parser_version = 61; else if (tokens.length == 54) parser_version = 70; else if (tokens.length == 61) parser_version = 80; outputMessage.put(ParserVersion, parser_version); if (!empty_attribute(tokens[31])) outputMessage.put(Bytes, tokens[31].trim()); if (!empty_attribute(tokens[32])) outputMessage.put(BytesSent, tokens[32].trim()); if (!empty_attribute(tokens[33])) outputMessage.put(BytesReceived, tokens[33].trim()); if (!empty_attribute(tokens[34])) outputMessage.put(Packets, tokens[34].trim()); if (!empty_attribute(tokens[35])) outputMessage.put(StartTime, tokens[35].trim()); if (!empty_attribute(tokens[36])) outputMessage.put(ElapsedTimeInSec, tokens[36].trim()); if (!empty_attribute(tokens[37])) outputMessage.put(Category, unquoted_attribute(tokens[37])); if (!empty_attribute(tokens[39])) outputMessage.put(Seqno, tokens[39].trim()); if (!empty_attribute(tokens[40])) outputMessage.put(ActionFlags, unquoted_attribute(tokens[40])); if (!empty_attribute(tokens[41])) outputMessage.put(SourceLocation, unquoted_attribute(tokens[41])); if (!empty_attribute(tokens[42])) outputMessage.put(DestinationLocation, unquoted_attribute(tokens[42])); if (!empty_attribute(tokens[44])) outputMessage.put(PktsSent, tokens[44].trim()); if (!empty_attribute(tokens[45])) outputMessage.put(PktsReceived, tokens[45].trim()); if (parser_version >= 61) { if (!empty_attribute(tokens[46])) outputMessage.put(EndReason, unquoted_attribute(tokens[46])); } if (parser_version >= 70) { if (!empty_attribute(tokens[47])) outputMessage.put(DGH1, tokens[47].trim()); if (!empty_attribute(tokens[48])) outputMessage.put(DGH2, tokens[48].trim()); if (!empty_attribute(tokens[49])) outputMessage.put(DGH3, tokens[49].trim()); if (!empty_attribute(tokens[50])) outputMessage.put(DGH4, tokens[50].trim()); if (!empty_attribute(tokens[51])) outputMessage.put(VSYSName, unquoted_attribute(tokens[51])); if (!empty_attribute(tokens[52])) outputMessage.put(DeviceName, unquoted_attribute(tokens[52])); if (!empty_attribute(tokens[53])) outputMessage.put(ActionSource, unquoted_attribute(tokens[53])); } if (parser_version >= 80) { if (!empty_attribute(tokens[54])) outputMessage.put(SourceVmUuid, tokens[54].trim()); if (!empty_attribute(tokens[55])) outputMessage.put(DestinationVmUuid, tokens[55].trim()); if (!empty_attribute(tokens[56])) outputMessage.put(TunnelId, tokens[56].trim()); if (!empty_attribute(tokens[57])) outputMessage.put(MonitorTag, tokens[57].trim()); if (!empty_attribute(tokens[58])) outputMessage.put(ParentSessionId, tokens[58].trim()); if (!empty_attribute(tokens[59])) outputMessage.put(ParentSessionStartTime, tokens[59].trim()); if (!empty_attribute(tokens[60])) outputMessage.put(TunnelType, tokens[60].trim()); } if (parser_version == 0) { outputMessage.put(Tokens, tokens.length); } } }
From source file:edu.umn.msi.tropix.webgui.server.ObjectServiceImpl.java
@ServiceMethod public void cloneAsGroupSharedFolder(final String folderId, final String groupId, final List<String> userIds, final List<String> groupIds) { this.tropixObjectService.cloneAsGroupSharedFolder(this.userSession.getGridId(), groupId, folderId, Iterables.toArray(userIds, String.class), Iterables.toArray(groupIds, String.class)); }
From source file:ru.ksu.niimm.cll.mocassin.crawl.parser.gate.util.AnnotationUtilImpl.java
@Override public String[] getPureTokensForAnnotation(Document document, Annotation annotation, boolean useStemming) { List<Annotation> tokenList = getSortedTokenList(document, annotation, false); List<String> strTokens = new ArrayList<String>(); for (Annotation a : tokenList) { String kind = (String) a.getFeatures().get("kind"); if (!kind.equals("word")) continue; String tokenFeatureName = useStemming ? GateFormatConstants.STEM_FEATURE_NAME : GateFormatConstants.TOKEN_FEATURE_NAME; String tokenValue = (String) a.getFeatures().get(tokenFeatureName); strTokens.add(tokenValue);/* w ww .j av a 2 s .c o m*/ } return Iterables.toArray(strTokens, String.class); }
From source file:org.spongepowered.common.mixin.core.server.management.MixinPlayerProfileCache.java
@Override public Map<String, Optional<GameProfile>> lookupByNames(Iterable<String> names) { checkNotNull(names, "names"); Map<String, Optional<GameProfile>> result = Maps.newHashMap(); this.getServer().getGameProfileRepository().findProfilesByNames(Iterables.toArray(names, String.class), Agent.MINECRAFT, new MapProfileLookupCallback(result)); if (!result.isEmpty()) { for (Optional<GameProfile> entry : result.values()) { if (entry.isPresent()) { this.addEntry((com.mojang.authlib.GameProfile) entry.get(), null); }// www. j av a 2 s . c o m } return ImmutableMap.copyOf(result); } else { return ImmutableMap.of(); } }
From source file:brooklyn.util.task.Tasks.java
public static Task<List<?>> parallel(String name, Iterable<? extends TaskAdaptable<?>> tasks) { return parallelInternal(name, asTasks(Iterables.toArray(tasks, TaskAdaptable.class))); }
From source file:net.joala.dns.NameStore.java
/** * <p>//from w ww . j a v a 2 s . co m * Lookup registered inet addresses for given name. * </p> * * @param name the host name * @return the inet addresses found for the given name; empty list if none */ @Nonnull InetAddress[] lookup(@Nonnull final Name name) { checkNotNull(name, CHECK_NAME_MUST_NOT_BE_NULL); synchronized (store) { if (store.containsKey(name)) { LOG.info(format("Succeeded to lookup %s.", name)); return Iterables.toArray(store.get(name), InetAddress.class); } } LOG.info(format("Failed to lookup %s.", name)); return new InetAddress[0]; }
From source file:org.blip.workflowengine.transferobject.ModifiablePropertyNode.java
@Override public PropertyNode add(final String key, final Float value, final Collection<Attribute> attributes) { return internalAdd(true, key, value, Iterables.toArray(attributes, Attribute.class)); }
From source file:org.atteo.config.Configuration.java
/** * Create Configuration by manually specifying all {@link Configurable}s. * @param klasses list of {@link Configurable} classes. * @throws JAXBException when JAXB context creation fails *///w w w. j a v a 2 s . c o m public Configuration(Iterable<Class<? extends Configurable>> klasses) { this.klasses = klasses; propertyFilter = Filtering.getFilter((PropertyResolver) (String name, PropertyFilter filter) -> { throw new PropertyNotFoundException(name); }); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); try { builder = factory.newDocumentBuilder(); // register null error handler, fatal errors will be reported with exception anyway builder.setErrorHandler(new ErrorHandler() { @Override public void warning(SAXParseException exception) throws SAXException { } @Override public void error(SAXParseException exception) throws SAXException { } @Override public void fatalError(SAXParseException exception) throws SAXException { } }); context = JAXBContextFactory.createContext(Iterables.toArray(klasses, Class.class), Collections.emptyMap()); binder = context.createBinder(); // JAXB Moxy does not allow to set resolver on binder // binder.setProperty(UnmarshallerProperties.ID_RESOLVER, new ScopedIdResolver()); binder.setEventHandler((ValidationEvent event) -> true); document = builder.newDocument(); } catch (ParserConfigurationException e) { throw new RuntimeException("Cannot configure XML parser", e); } catch (JAXBException e) { throw new RuntimeException("Cannot configure unmarshaller", e); } }
From source file:org.apache.jackrabbit.oak.plugins.index.property.jmx.PropertyIndexStats.java
private String[] determineIndexedPaths(Iterable<? extends ChildNodeEntry> values, final int maxDepth, int maxPathCount) { Set<String> paths = Sets.newHashSet(); Set<String> intermediatePaths = Sets.newHashSet(); int maxPathLimitBreachedAtLevel = -1; topLevel: for (ChildNodeEntry cne : values) { Tree t = TreeFactory.createReadOnlyTree(cne.getNodeState()); TreeTraverser<Tree> traverser = new TreeTraverser<Tree>() { @Override//from w w w. j a v a2 s . co m public Iterable<Tree> children(@Nonnull Tree root) { //Break at maxLevel if (PathUtils.getDepth(root.getPath()) >= maxDepth) { return Collections.emptyList(); } return root.getChildren(); } }; for (Tree node : traverser.breadthFirstTraversal(t)) { PropertyState matchState = node.getProperty("match"); boolean match = matchState == null ? false : matchState.getValue(Type.BOOLEAN); int depth = PathUtils.getDepth(node.getPath()); //Intermediate nodes which are not leaf are not to be included if (depth < maxDepth && !match) { intermediatePaths.add(node.getPath()); continue; } if (paths.size() < maxPathCount) { paths.add(node.getPath()); } else { maxPathLimitBreachedAtLevel = depth; break topLevel; } } } if (maxPathLimitBreachedAtLevel < 0) { return Iterables.toArray(paths, String.class); } //If max limit for path is reached then we can safely //say about includedPaths upto depth = level at which limit reached - 1 //As for that level we know *all* the path roots Set<String> result = Sets.newHashSet(); int safeDepth = maxPathLimitBreachedAtLevel - 1; if (safeDepth > 0) { for (String path : intermediatePaths) { int pathDepth = PathUtils.getDepth(path); if (pathDepth == safeDepth) { result.add(path); } } } return Iterables.toArray(result, String.class); }
From source file:grakn.core.graql.gremlin.fragment.Fragments.java
/** * A type-safe way to do `a.union(b, c)`, as `Fragments.union(a, ImmutableSet.of(b, c))`. * This avoids issues with unchecked varargs. */// ww w . jav a2 s.co m static <S, E1, E2> GraphTraversal<S, E2> union(GraphTraversal<S, ? extends E1> start, Iterable<GraphTraversal<? super E1, ? extends E2>> traversals) { // This is safe, because we know all the arguments are of the right type //noinspection unchecked GraphTraversal<E1, E2>[] array = (GraphTraversal<E1, E2>[]) Iterables.toArray(traversals, GraphTraversal.class); return start.union(array); }