code
stringlengths
73
34.1k
label
stringclasses
1 value
public SmbTransport getDc(String domain, SmbExtendedAuthenticator authenticator, NtlmPasswordAuthentication auth) throws SmbAuthException { // public SmbTransport getDc(String domain, // NtlmPasswordAuthentication auth) throws SmbAuthException { // SmbAuthenticator<< if (DISAB...
java
public static boolean addAll(LongCollection collection, long[] array) { boolean changed = false; for (long element : array) { changed |= collection.add(element); } return changed; }
java
@Nullable public static <T> T get(T[] array, int index) { return array != null && index >= 0 && index < array.length ? array[index] : null; }
java
public static <T> T[] slice(T[] array, int... indexes) { int length = indexes.length; T[] slice = ObjectArrays.newArray(array, length); for (int i = 0; i < length; i++) { slice[i] = array[indexes[i]]; } return slice; }
java
public static <T> List<T> slice(List<T> list, int... indexes) { List<T> slice = new ArrayList<>(indexes.length); for (int i : indexes) { slice.add(list.get(i)); } return slice; }
java
public static Class<?> getClass(Object obj) { Class<?> cls = obj.getClass(); return cls != Class.class ? cls : (Class<?>) obj; }
java
public static Class<?> getNamedClass(Object obj) { Class<?> cls = getClass(obj); while (cls != null && cls.isAnonymousClass()) { cls = cls.getEnclosingClass(); } return cls; }
java
public static Request request(String url, String... headers) { Request.Builder request = new Request.Builder().url(url); if (headers != null) { int length = headers.length; checkArgument(length % 2 == 0, "headers length must be a multiple of two"); for (int i = 0; i < length; i += 2) { request.addHeade...
java
public Call call(String url, String... headers) { return mCaller.newCall(request(url, headers)); }
java
public Response response(String url, String... headers) throws IOException { return call(url, headers).execute(); }
java
public Response download(String url, File destination) throws IOException { return download(url, destination, (String[]) null); }
java
public Response download(String url, File destination, String... headers) throws IOException { try (Response resp = response(url, headers)) { if (resp.isSuccessful()) { try (BufferedSink sink = Okio.buffer(Okio.sink(destination))) { resp.body().source().readAll(sink); } } return resp; } }
java
@Default public int getOffset() { String value = getValue(); String superstring = getSuperstring(); return value != null && superstring != null ? superstring.indexOf(value) : -1; }
java
public String getString() { StringBuffer buf = new StringBuffer(); for (int i = 0; i != string.length; i++) { buf.append(table[(string[i] >>> 4) % 0xf]); buf.append(table[string[i] & 0xf]); } return buf.toString(); }
java
public static int clamp(int value, int min, int max) { return Math.min(Math.max(min, value), max); }
java
public static String normalise(String s) { if (sDiacritics == null) { sDiacritics = Pattern.compile("\\p{InCombiningDiacriticalMarks}+"); } return sDiacritics.matcher(Normalizer.normalize(s, NFD)).replaceAll("").toUpperCase(US); }
java
public static String distance(String latitudeColumn, String longitudeColumn, String latitudeCosineColumn, double latitude, double longitude, MeasureUnit unit, String alias) { double degree = unit == MILE ? LATITUDE_DEGREE_MI : LATITUDE_DEGREE_KM; return String.format((Locale) null, sDistance, degree, latitude...
java
public static void sleep(long length, TimeUnit unit) { try { unit.sleep(length); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } }
java
boolean matches(SmbExtendedAuthenticator authenticator, NtlmPasswordAuthentication auth) { return matcheObject(this.authenticator, authenticator) && matcheObject(this.auth, auth); }
java
Key searchSessionKey(Subject subject) throws GSSException{ /* The kerberos session key is not accessible via the JGSS API IBM and Oracle both implement a similar API to make an ExtendedGSSContext available. The older implementation to find the session key is still...
java
static protected int getPadBits( int bitString) { int val; if (bitString == 0) { return 7; } if (bitString > 255) { val = ((bitString >> 8) & 0xFF); } else { val = (bitString & 0xFF)...
java
static protected byte[] getBytes( int bitString) { if (bitString > 255) { byte[] bytes = new byte[2]; bytes[0] = (byte)(bitString & 0xFF); bytes[1] = (byte)((bitString >> 8) & 0xFF); return bytes; } else ...
java
public static PreparedStatement setStrings(PreparedStatement stmt, String... params) throws SQLException { return setStrings(1, stmt, params); }
java
public static int firstInt(PreparedStatement stmt) throws SQLException { ResultSet rs = stmt.executeQuery(); int i = rs.next() ? rs.getInt(1) : Integer.MIN_VALUE; stmt.close(); return i; }
java
public static long firstLong(PreparedStatement stmt) throws SQLException { ResultSet rs = stmt.executeQuery(); long l = rs.next() ? rs.getLong(1) : Long.MIN_VALUE; stmt.close(); return l; }
java
@Nullable public static String firstString(PreparedStatement stmt) throws SQLException { ResultSet rs = stmt.executeQuery(); String s = rs.next() ? rs.getString(1) : null; stmt.close(); return s; }
java
@SuppressWarnings("unchecked") public static List<String> firstStringRow(PreparedStatement stmt) throws SQLException { return (List<String>) firstRow(stmt, String.class); }
java
@SuppressWarnings("unchecked") public static List<String> allStrings(PreparedStatement stmt) throws SQLException { return (List<String>) all(stmt, String.class); }
java
public static int firstIntKey(PreparedStatement stmt) throws SQLException { stmt.execute(); ResultSet rs = stmt.getGeneratedKeys(); int key = rs.next() ? rs.getInt(1) : 0; stmt.close(); return key; }
java
public static long firstLongKey(PreparedStatement stmt) throws SQLException { stmt.execute(); ResultSet rs = stmt.getGeneratedKeys(); long key = rs.next() ? rs.getLong(1) : 0L; stmt.close(); return key; }
java
public static int update(PreparedStatement stmt) throws SQLException { int rows = stmt.executeUpdate(); stmt.close(); return rows; }
java
public static Cpe parse(String cpeString, boolean lenient) throws CpeParsingException { if (cpeString == null) { throw new CpeParsingException("CPE String is null and cannot be parsed"); } else if (cpeString.regionMatches(0, "cpe:/", 0, 5)) { return parse22(cpeString, lenient); ...
java
protected static Cpe parse22(String cpeString, boolean lenient) throws CpeParsingException { if (cpeString == null || cpeString.isEmpty()) { throw new CpeParsingException("CPE String is null ir enpty - unable to parse"); } CpeBuilder cb = new CpeBuilder(); String[] parts = cp...
java
protected static void unpackEdition(String edition, CpeBuilder cb, boolean lenient) throws CpeParsingException { if (edition == null || edition.isEmpty()) { return; } try { String[] unpacked = edition.split("~"); if (edition.startsWith("~")) { ...
java
protected static Cpe parse23(String cpeString, boolean lenient) throws CpeParsingException { if (cpeString == null || cpeString.isEmpty()) { throw new CpeParsingException("CPE String is null ir enpty - unable to parse"); } CpeBuilder cb = new CpeBuilder(); Cpe23PartIterator c...
java
public static Status component(String value) { if (value != null && !value.isEmpty()) { if ("\\-".equals(value)) { return Status.SINGLE_QUOTED_HYPHEN; } for (int x = 0; x < value.length(); x++) { char c = value.charAt(x); if (c ...
java
private static long countCharacter(String value, char c) { return value.chars().filter(s -> s == c).count(); }
java
public static Status cpe(String value) { if ("cpe:2.3:".regionMatches(0, value, 0, 8)) { return formattedString(value); } return cpeUri(value); }
java
public static String fromWellFormed(String value) { if (value == null) { return LogicalValue.ANY.getAbbreviation(); } //return value.replaceAll("\\\\([^0-9A-Za-z])", "$1"); StringBuilder buffer = new StringBuilder(value); char p = ' '; for (int x = 0; x < buff...
java
public static String wellFormedToFS(Part value) { if (value == null) { return LogicalValue.ANY.getAbbreviation(); } return value.getAbbreviation(); }
java
public static Pattern wellFormedToPattern(String value) { StringBuilder sb = new StringBuilder(value.length() + 4); for (int x = 0; x < value.length(); x++) { if (value.charAt(x) == '*') { sb.append(".*"); } else if (value.charAt(x) == '?') { sb.ap...
java
private void validate(String vendor1, String product1, String version1, String update1, String edition1, String language1, String swEdition1, String targetSw1, String targetHw1, String other1) throws CpeValidationException { Status status = Validate.component(vendor1); if (!statu...
java
@Override public String toCpe22Uri() throws CpeEncodingException { StringBuilder sb = new StringBuilder("cpe:/"); sb.append(Convert.wellFormedToCpeUri(part)).append(":"); sb.append(Convert.wellFormedToCpeUri(vendor)).append(":"); sb.append(Convert.wellFormedToCpeUri(product)).append(...
java
@Override public String toCpe23FS() { return String.format("cpe:2.3:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s", Convert.wellFormedToFS(part), Convert.wellFormedToFS(vendor), Convert.wellFormedToFS(product), Convert.wellFormedToFS(version), ...
java
@Override public boolean matches(ICpe target) { boolean result = true; result &= compareAttributes(this.part, target.getPart()); result &= compareAttributes(this.vendor, target.getWellFormedVendor()); result &= compareAttributes(this.product, target.getWellFormedProduct()); r...
java
private static boolean containsSpecialCharacter(String value) { for (int x = 0; x < value.length(); x++) { char c = value.charAt(x); if (c == '?' || c == '*') { return true; } else if (c == '\\') { //skip the next character because it is quoted...
java
@Override public int compareTo(Object o) { if (o instanceof ICpe) { ICpe otherObject = (ICpe) o; final int before = -1; final int equal = 0; final int after = 1; if (this == otherObject) { return equal; } i...
java
protected static int compareVersions(String left, String right) { int result = 0; //while the strings are well formed - the backslashes will be in the exact //same location in equal strings - for version numbers the cost of conversion //should not be incurred //final List<String>...
java
protected void reset() { part = Part.ANY; vendor = LogicalValue.ANY.getAbbreviation(); product = LogicalValue.ANY.getAbbreviation(); version = LogicalValue.ANY.getAbbreviation(); update = LogicalValue.ANY.getAbbreviation(); edition = LogicalValue.ANY.getAbbreviation(); ...
java
public void add(E element) { if (element == null) throw new NullPointerException(); if (root == null) { root = new MutableNode<>(element); } else { MutableNode<E> node = root; while (!node.getElement().equals(element)) { int distance = distanc...
java
public Set<Match<? extends E>> search(E query, int maxDistance) { if (query == null) throw new NullPointerException(); if (maxDistance < 0) throw new IllegalArgumentException("maxDistance must be non-negative"); Metric<? super E> metric = tree.getMetric(); Set<Match<? extends E>> match...
java
public boolean isLogger(String loggerName) throws Exception { Address addr = Address.root().add(SUBSYSTEM, LOGGING, LOGGER, loggerName); return null != readResource(addr); }
java
public String getLoggerLevel(String loggerName) throws Exception { Address addr = Address.root().add(SUBSYSTEM, LOGGING, LOGGER, loggerName); return getStringAttribute("level", addr); }
java
public void setLoggerLevel(String loggerName, String level) throws Exception { final Address addr = Address.root().add(SUBSYSTEM, LOGGING, LOGGER, loggerName); final ModelNode request; if (isLogger(loggerName)) { request = createWriteAttributeRequest("level", level, addr); ...
java
public boolean isWebSubsystem() throws Exception { Address addr = Address.root().add(SUBSYSTEM, SUBSYSTEM_WEB); return null != readResource(addr); }
java
public void setEnableWelcomeRoot(boolean enableFlag) throws Exception { final Address address = Address.root().add(SUBSYSTEM, SUBSYSTEM_WEB, VIRTUAL_SERVER, DEFAULT_HOST); final ModelNode req = createWriteAttributeRequest("enable-welcome-root", Boolean.toString(enableFlag), address); final Model...
java
public boolean isConnector(String name) throws Exception { final Address address = Address.root().add(SUBSYSTEM, SUBSYSTEM_WEB, CONNECTOR, name); return null != readResource(address); }
java
public ModelNode getConnector(String name) throws Exception { final Address address = Address.root().add(SUBSYSTEM, SUBSYSTEM_WEB, CONNECTOR, name); return readResource(address, true); }
java
public void changeConnector(String connectorName, String attribName, String attribValue) throws Exception { final Address address = Address.root().add(SUBSYSTEM, SUBSYSTEM_WEB, CONNECTOR, connectorName); final ModelNode op = createWriteAttributeRequest(attribName, attribValue, address); final Mo...
java
public void removeConnector(String doomedConnectorName) throws Exception { final Address address = Address.root().add(SUBSYSTEM, SUBSYSTEM_WEB, CONNECTOR, doomedConnectorName); if (isConnector(doomedConnectorName)) { remove(address); } return; }
java
public static ModelNode createWriteAttributeRequest(String attributeName, String attributeValue, Address address) { final ModelNode op = createRequest(WRITE_ATTRIBUTE, address); op.get(NAME).set(attributeName); setPossibleExpression(op, VALUE, attributeValue); return op; }
java
public static ModelNode createRequest(String operation, Address address) { return createRequest(operation, address, null); }
java
public static ModelNode createRequest(String operation, Address address, ModelNode extra) { final ModelNode request = (extra != null) ? extra.clone() : new ModelNode(); request.get(OPERATION).set(operation); request.get(ADDRESS).set(address.getAddressNode()); return request; }
java
public static ModelNode createBatchRequest(ModelNode... steps) { final ModelNode composite = new ModelNode(); composite.get(OPERATION).set(BATCH); composite.get(ADDRESS).setEmptyList(); final ModelNode stepsNode = composite.get(BATCH_STEPS); for (ModelNode step : steps) { ...
java
public static ModelNode getResults(ModelNode operationResult) { if (!operationResult.hasDefined(RESULT)) { return new ModelNode(); } return operationResult.get(RESULT); }
java
public ModelNode execute(ModelNode request) throws Exception { ModelControllerClient mcc = getModelControllerClient(); return mcc.execute(request, OperationMessageHandler.logging); }
java
public void remove(Address doomedAddr) throws Exception { final ModelNode request = createRequest(REMOVE, doomedAddr); final ModelNode response = execute(request); if (!isSuccess(response)) { throw new FailureException(response, "Failed to remove resource at address [" + doomedAddr +...
java
public void deploy(String deploymentName, InputStream content, boolean enabled, Set<String> serverGroups, boolean forceDeploy) { if (serverGroups == null) { serverGroups = Collections.emptySet(); } DeploymentResult result = null; try { DeploymentMana...
java
public void undeploy(String deploymentName, Set<String> serverGroups, boolean removeContent) { if (serverGroups == null) { serverGroups = Collections.emptySet(); } DeploymentResult result = null; try { DeploymentManager dm = DeploymentManager.Factory.create(getM...
java
public boolean isVault() throws Exception { Address addr = Address.root().add(CORE_SERVICE, VAULT); final ModelNode queryNode = createRequest(READ_RESOURCE, addr); final ModelNode results = execute(queryNode); if (isSuccess(results)) { return true; } return f...
java
public String getVaultClass() throws Exception { Address addr = Address.root().add(CORE_SERVICE, VAULT); ModelNode vaultNode = readResource(addr); if (vaultNode == null) { return null; } ModelNode codeNode = vaultNode.get("code"); if (codeNode == null) { ...
java
public ModelNode createNewVaultRequest(String className) { String dmrTemplate = "" // + "{" // + "\"code\" => \"%s\"" + "}"; String dmr = String.format(dmrTemplate, className); Address addr = Address.root().add(CORE_SERVICE, VAULT); final ModelNode r...
java
public void setEnableAdminConsole(boolean enableFlag) throws Exception { final Address address = Address.root() .add(CORE_SERVICE, CORE_SERVICE_MGMT, MGMT_INTERFACE, MGMT_INTERFACE_HTTP); final ModelNode req = createWriteAttributeRequest("console-enabled", Boolean.toString(enableFlag), a...
java
public Properties getSystemProperties() throws Exception { final String[] address = { CORE_SERVICE, PLATFORM_MBEAN, "type", "runtime" }; final ModelNode op = createReadAttributeRequest(true, "system-properties", Address.root().add(address)); final ModelNode results = execute(op); if (isS...
java
public void setAppServerDefaultDeploymentScanEnabled(boolean enabled) throws Exception { final String[] addressArr = { SUBSYSTEM, DEPLOYMENT_SCANNER, SCANNER, "default" }; final Address address = Address.root().add(addressArr); final ModelNode req = createWriteAttributeRequest("scan-enabled", Bo...
java
public String getAppServerDefaultDeploymentDir() throws Exception { final String[] addressArr = { SUBSYSTEM, DEPLOYMENT_SCANNER, SCANNER, "default" }; final Address address = Address.root().add(addressArr); final ModelNode resourceAttributes = readResource(address); if (resourceAttribut...
java
public void setAppServerDefaultDeploymentTimeout(long secs) throws Exception { final String[] addressArr = { SUBSYSTEM, DEPLOYMENT_SCANNER, SCANNER, "default" }; final Address address = Address.root().add(addressArr); final ModelNode req = createWriteAttributeRequest("deployment-timeout", Long.t...
java
public void setSystemProperty(String name, String value) throws Exception { final ModelNode request = createRequest(ADD, Address.root().add(SYSTEM_PROPERTY, name)); request.get(VALUE).set(value); final ModelNode response = execute(request); if (!isSuccess(response)) { throw n...
java
public void addExtension(String name) throws Exception { // /extension=<name>/:add(module=<name>) final ModelNode request = createRequest(ADD, Address.root().add(EXTENSION, name)); request.get(MODULE).set(name); final ModelNode response = execute(request); if (!isSuccess(response...
java
public boolean isExtension(String name) throws Exception { return null != readResource(Address.root().add(EXTENSION, name)); }
java
public boolean isSubsystem(String name) throws Exception { return null != readResource(Address.root().add(SUBSYSTEM, name)); }
java
public void reload(boolean adminOnly) throws Exception { final ModelNode request = createRequest("reload", Address.root()); request.get("admin-only").set(adminOnly); final ModelNode response = execute(request); if (!isSuccess(response)) { throw new FailureException(response);...
java
public void shutdown(boolean restart) throws Exception { final ModelNode request = createRequest("shutdown", Address.root()); request.get("restart").set(restart); final ModelNode response = execute(request); if (!isSuccess(response)) { throw new FailureException(response); ...
java
public boolean isQueue(String queueName) throws Exception { Address addr = Address.root().add(SUBSYSTEM, SUBSYSTEM_MESSAGING, HORNETQ_SERVER, "default"); String haystack = JMS_QUEUE; return null != findNodeInList(addr, haystack, queueName); }
java
public ModelNode createNewQueueRequest(String name, Boolean durable, List<String> entryNames) { String dmrTemplate = "" // + "{" // + "\"durable\" => \"%s\", " // + "\"entries\" => [\"%s\"] " // + "}"; String dmr = String.format(dmrTemplate, ((null == du...
java
@SuppressWarnings("unchecked") public static <T> T[] cloneArray(T[] original) { if (original == null) { return null; } try { Class<?> clazz = original.getClass().getComponentType(); T[] copy = (T[]) Array.newInstance(clazz, original.length); i...
java
public boolean isSecurityDomain(String securityDomainName) throws Exception { Address addr = Address.root().add(SUBSYSTEM, SUBSYSTEM_SECURITY); String haystack = SECURITY_DOMAIN; return null != findNodeInList(addr, haystack, securityDomainName); }
java
public void createNewSecureIdentitySecurityDomain72(String securityDomainName, String username, String password) throws Exception { Address addr = Address.root().add(SUBSYSTEM, SUBSYSTEM_SECURITY, SECURITY_DOMAIN, securityDomainName); ModelNode addTopNode = createRequest(ADD, addr); ...
java
public ModelNode getSecureIdentitySecurityDomainModuleOptions(String securityDomainName) throws Exception { Address addr = Address.root().add(SUBSYSTEM, SUBSYSTEM_SECURITY, SECURITY_DOMAIN, securityDomainName, AUTHENTICATION, CLASSIC); ModelNode authResource = readResource(addr); ...
java
public void removeSecurityDomain(String securityDomainName) throws Exception { // If not there just return if (!isSecurityDomain(securityDomainName)) { return; } final Address addr = Address.root().add(SUBSYSTEM, SUBSYSTEM_SECURITY, SECURITY_DOMAIN, securityDomainName); ...
java
public void createNewSecurityDomain(String securityDomainName, LoginModuleRequest... loginModules) throws Exception { //do not close the controller client here, we're using our own.. CoreJBossASClient coreClient = new CoreJBossASClient(getModelControllerClient()); String serverVersio...
java
public boolean securityDomainHasLoginModule(String domainName, String moduleName) throws Exception { Address addr = Address.root().add(SUBSYSTEM, SUBSYSTEM_SECURITY, SECURITY_DOMAIN, domainName); addr.add(AUTHENTICATION, CLASSIC); addr.add(LOGIN_MODULE, moduleName); ModelNode request = c...
java
private static <L> void populateMetricTypesForResourceType( ResourceType.Builder<?, L> resourceTypeBuilder, TypeSets.Builder<L> typeSetsBuilder) { Map<Name, TypeSet<MetricType<L>>> metricTypeSets = typeSetsBuilder.getMetricTypeSets(); List<Name> metricSetNames = resourceTypeBuil...
java
public <N, S extends Session<L>> void discoverChildren( Resource<L> parent, ResourceType<L> childType, Session<L> session, EndpointService<L, S> service, Consumer<Resource<L>> resourceConsumer) { try { L parentLocation = parent != null ? ...
java
public void doScrape() throws Exception { MBeanServerConnection beanConn; JMXConnector jmxc = null; if (jmxUrl.isEmpty()) { beanConn = ManagementFactory.getPlatformMBeanServer(); } else { Map<String, Object> environment = new HashMap<String, Object>(); ...
java
public boolean isCacheContainer(String cacheContainerName) throws Exception { Address addr = Address.root().add(SUBSYSTEM, SUBSYSTEM_INFINISPAN); String haystack = CACHE_CONTAINER; return null != findNodeInList(addr, haystack, cacheContainerName); }
java
public boolean isLocalCache(String cacheContainerName, String localCacheName) throws Exception { if (!isCacheContainer(cacheContainerName)) { return false; } Address addr = Address.root().add(SUBSYSTEM, SUBSYSTEM_INFINISPAN, CACHE_CONTAINER, cacheContainerName); String hayst...
java
public boolean isJDBCDriver(String jdbcDriverName) throws Exception { Address addr = Address.root().add(SUBSYSTEM, SUBSYSTEM_DATASOURCES); String haystack = JDBC_DRIVER; return null != findNodeInList(addr, haystack, jdbcDriverName); }
java
public boolean isDatasource(String datasourceName) throws Exception { Address addr = Address.root().add(SUBSYSTEM, SUBSYSTEM_DATASOURCES); String haystack = DATA_SOURCE; return null != findNodeInList(addr, haystack, datasourceName); }
java
public boolean isXADatasource(String datasourceName) throws Exception { Address addr = Address.root().add(SUBSYSTEM, SUBSYSTEM_DATASOURCES); String haystack = XA_DATA_SOURCE; return null != findNodeInList(addr, haystack, datasourceName); }
java