public void SetItems() { itemsView = (ListView) findViewById(R.id.myItemsListView); if (NetworkUtil.getConnectivityStatus(this) == 1) { usersItems = user.getMyItems(); itemsList = new String[usersItems.size()]; itemsList = usersItems.toArray(itemsList); ItemController.getItemsByIDElasticSearch(itemsList); usersItemsArrayList = ItemController.getItemList().getItemList(); for (Item item : usersItemsArrayList) { if (item.getAvailability()) { usersItemsArrayList.remove(item); } } if (usersItemsArrayList.isEmpty()) { Toast.makeText( ViewBorrowingOutActivity.this, "None of your items are being borrowed.", Toast.LENGTH_SHORT) .show(); } // TODO: can stop converting the items list into String[] once that's it's actual type adapter = new CustomSearchResultsAdapter(this, usersItemsArrayList); itemsView.setAdapter(adapter); adapter.notifyDataSetChanged(); } else { Toast.makeText(this, "You are not connected to the internet.", Toast.LENGTH_SHORT).show(); } }
/** * Initialize the backend systems, the log handler and the restrictor. A subclass can tune this * step by overriding {@link #createRestrictor(String)} and {@link * #createLogHandler(ServletConfig, boolean)} * * @param pServletConfig servlet configuration */ @Override public void init(ServletConfig pServletConfig) throws ServletException { super.init(pServletConfig); Configuration config = initConfig(pServletConfig); // Create a log handler early in the lifecycle, but not too early String logHandlerClass = config.get(ConfigKey.LOGHANDLER_CLASS); logHandler = logHandlerClass != null ? (LogHandler) ClassUtil.newInstance(logHandlerClass) : createLogHandler(pServletConfig, Boolean.valueOf(config.get(ConfigKey.DEBUG))); // Different HTTP request handlers httpGetHandler = newGetHttpRequestHandler(); httpPostHandler = newPostHttpRequestHandler(); if (restrictor == null) { restrictor = createRestrictor(NetworkUtil.replaceExpression(config.get(ConfigKey.POLICY_LOCATION))); } else { logHandler.info("Using custom access restriction provided by " + restrictor); } configMimeType = config.get(ConfigKey.MIME_TYPE); backendManager = new BackendManager(config, logHandler, restrictor); requestHandler = new HttpRequestHandler(config, backendManager, logHandler); initDiscoveryMulticast(config); }
// Adding a WEP network private int changeNetworkWEP(NetworkSetting input) { WifiConfiguration config = changeNetworkCommon(input); String pass = input.getPassword(); if (NetworkUtil.isHexWepKey(pass)) { config.wepKeys[0] = pass; } else { config.wepKeys[0] = NetworkUtil.convertToQuotedString(pass); } config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104); config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); config.wepTxKeyIndex = 0; return requestNetworkChange(config); }
@Override public void encodeInto(ChannelHandlerContext context, ByteBuf buffer) { buffer.writeInt(this.type.ordinal()); try { NetworkUtil.encodeData(buffer, this.data); } catch (IOException e) { e.printStackTrace(); } }
// Try to find an URL for system props or config private String findAgentUrl(Configuration pConfig) { // System property has precedence String url = System.getProperty("jolokia." + ConfigKey.DISCOVERY_AGENT_URL.getKeyValue()); if (url == null) { url = System.getenv("JOLOKIA_DISCOVERY_AGENT_URL"); if (url == null) { url = pConfig.get(ConfigKey.DISCOVERY_AGENT_URL); } } return NetworkUtil.replaceExpression(url); }
// Examines servlet config and servlet context for configuration parameters. // Configuration from the servlet context overrides servlet parameters defined in web.xml Configuration initConfig(ServletConfig pConfig) { Configuration config = new Configuration(ConfigKey.AGENT_ID, NetworkUtil.getAgentId(hashCode(), "servlet")); // From ServletContext .... config.updateGlobalConfiguration(new ServletConfigFacade(pConfig)); // ... and ServletConfig config.updateGlobalConfiguration(new ServletContextFacade(getServletContext())); // Set type last and overwrite anything written config.updateGlobalConfiguration( Collections.singletonMap(ConfigKey.AGENT_TYPE.getKeyValue(), "servlet")); return config; }
@Override protected Drawable doInBackground(String... urls) { if (mNetworkUtil.isNetworkAvailable(mContext)) { try { InputStream is = (InputStream) new URL(urls[0]).getContent(); Drawable d = Drawable.createFromStream(is, "image"); return d; } catch (Exception e) { e.printStackTrace(); return mContext.getResources().getDrawable(R.drawable.ic_action_alert); } } else return mContext.getResources().getDrawable(R.drawable.ic_action_alert); }
public void testFindUsers() throws Exception { User[] users = myTransport.findUsers(new NullProgressIndicator()); assertTrue("At least self should be found", users.length >= 1); User self = null; for (User user : users) { if (user.getName().equals(StringUtil.getMyUsername())) { self = user; break; } } assertNotNull("Self user not found in " + Arrays.asList(users), self); assertTrue("Self should be online", self.isOnline()); InetAddress address = myTransport.getAddress(self); assertTrue("Self address is expected:" + address, NetworkUtil.isOwnAddress(address)); assertEquals("Projects should be set", PROJECT_NAME, self.getProjects()[0]); }
@Override public void decodeInto(ChannelHandlerContext context, ByteBuf buffer) { this.type = EnumSimplePacket.values()[buffer.readInt()]; try { if (this.type.getDecodeClasses().length > 0) { this.data = NetworkUtil.decodeData(this.type.getDecodeClasses(), buffer); } } catch (Exception e) { System.err.println( "[Galacticraft] Error handling simple packet type: " + this.type.toString() + " " + buffer.toString()); e.printStackTrace(); } }
// Update the agent URL in the agent details if not already done private void updateAgentDetailsIfNeeded(HttpServletRequest pReq) { // Lookup the Agent URL if needed AgentDetails details = backendManager.getAgentDetails(); if (details.isInitRequired()) { synchronized (details) { if (details.isInitRequired()) { if (details.isUrlMissing()) { String url = getBaseUrl( NetworkUtil.sanitizeLocalUrl(pReq.getRequestURL().toString()), extractServletPath(pReq)); details.setUrl(url); } if (details.isSecuredMissing()) { details.setSecured(pReq.getAuthType() != null); } details.seal(); } } } }
@Override protected Integer doInBackground(String... params) { if (mNetworkUtil.isNetworkAvailable(mContext)) { if (params[0].trim().length() > 0 && params[1].trim().length() > 0) { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(AUTHENTICATION_URL); try { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair(TAG_USERNAME, params[0].trim())); nameValuePairs.add(new BasicNameValuePair(TAG_PASSWORD, params[1].trim())); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); if (response.toString().equals("")) return SUCCESS; else return ERROR_WRONG_CREDENTIALS; } catch (Exception e) { e.printStackTrace(); return ERROR_EXCEPTION; } } else return ERROR_WRONG_INPUT; } else return ERROR_NO_CONNECTION; }
// Adding a WPA or WPA2 network private int changeNetworkWPA(NetworkSetting input) { WifiConfiguration config = changeNetworkCommon(input); String pass = input.getPassword(); // Hex passwords that are 64 bits long are not to be quoted. if (HEX_DIGITS_64.matcher(pass).matches()) { Log.d(TAG, "A 64 bit hex password entered."); config.preSharedKey = pass; } else { Log.d(TAG, "A normal password entered: I am quoting it."); config.preSharedKey = NetworkUtil.convertToQuotedString(pass); } config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); // For WPA config.allowedProtocols.set(WifiConfiguration.Protocol.WPA); // For WPA2 config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); config.allowedProtocols.set(WifiConfiguration.Protocol.RSN); return requestNetworkChange(config); }
private WifiConfiguration changeNetworkCommon(NetworkSetting input) { statusView.setText(R.string.wifi_creating_network); Log.d( TAG, "Adding new configuration: \nSSID: " + input.getSsid() + "\nType: " + input.getNetworkType()); WifiConfiguration config = new WifiConfiguration(); config.allowedAuthAlgorithms.clear(); config.allowedGroupCiphers.clear(); config.allowedKeyManagement.clear(); config.allowedPairwiseCiphers.clear(); config.allowedProtocols.clear(); // Android API insists that an ascii SSID must be quoted to be correctly handled. config.SSID = NetworkUtil.convertToQuotedString(input.getSsid()); config.hiddenSSID = true; return config; }
public EclTcpSession(InetAddress address, int port) throws IOException { NetworkUtil.initTimeouts(); this.address = address; this.port = port; try { initSocket(address, port, true); } catch (IOException e) { initSocket(address, port, false); EclTcpClientPlugin.logInfo( "Could not open a session with NO_DELAY and SO_REUSEADDR, succeeded with default socket"); } processingThread = new Thread( new Runnable() { public void run() { try { while (!closed.get()) { ExecutionNode node = null; IMarkeredPipe pipe = null; try { node = commands.take(); if (CLOSE_NODE.equals(node)) { return; } pipe = CoreUtils.createEMFPipe( socket.getInputStream(), socket.getOutputStream()); pipe.write(node.command); readInput(node.input, pipe); pipe.writeCloseMarker(); IStatus result = writeOutput(node.output, pipe); node.process.setStatus(result); } catch (Throwable t) { try { if (node != null) { IStatus status = (t instanceof CoreException) ? ((CoreException) t).getStatus() : CorePlugin.err(t); node.process.setStatus(new EclTcpSocketStatus(status)); } } catch (CoreException e1) { CorePlugin.log(e1); } } finally { if (pipe != null) { pipe.closeNoWait(); } } } } finally { try { closeSocket(); } catch (Throwable e) { CorePlugin.log(e); } } } }, "ECL TCP session execute: " + sessionID); processingThread.start(); }