List of usage examples for java.net InetAddress getByName
public static InetAddress getByName(String host) throws UnknownHostException
From source file:com.stratio.ingestion.sink.cassandra.EventParser.java
private static InetAddress parseInetSocketAddress(final String fieldValue) { try {/*from w w w . ja v a 2s . c o m*/ return InetAddress.getByName(fieldValue); } catch (UnknownHostException e) { throw new IllegalArgumentException(e); } }
From source file:org.signserver.client.cli.performance.PerformanceTestPDFServlet.java
License:asdf
/** @see org.signserver.client.PerformanceTestTask */ public boolean invoke(int threadId) { if (startTime == 0) { startTime = System.currentTimeMillis(); }/*w w w. ja v a 2 s . co m*/ byte[] testPDF = pdfs .get((int) ((System.currentTimeMillis() - startTime) * ((long) pdfs.size()) / runTime)); URL target; try { target = new URL(baseURLString); InetAddress addr = InetAddress.getByName(target.getHost()); Socket socket = new Socket(addr, target.getPort()); OutputStream raw = socket.getOutputStream(); final int contentLength = REQUEST_CONTENT_WORKERNAME.length() + REQUEST_CONTENT_FILE.length() + testPDF.length + REQUEST_CONTENT_END.length(); final String command = "POST " + target.getPath() + "pdf HTTP/1.0\r\n" + "Content-Type: multipart/form-data; boundary=signserver\r\n" + "Content-Length: " + contentLength + "\r\n" + "\r\n"; raw.write(command.getBytes()); raw.write(REQUEST_CONTENT_WORKERNAME.getBytes()); raw.write(REQUEST_CONTENT_FILE.getBytes()); raw.write(testPDF); raw.write(REQUEST_CONTENT_END.getBytes()); raw.flush(); InputStream in = socket.getInputStream(); ByteArrayOutputStream os = new ByteArrayOutputStream(); int len = 0; byte[] buf = new byte[1024]; while ((len = in.read(buf)) > 0) { os.write(buf, 0, len); } in.close(); os.close(); byte[] inbytes = os.toByteArray(); PdfReader pdfReader = new PdfReader(inbytes); if (!new String(pdfReader.getPageContent(1)).contains(PDF_CONTENT)) { System.err.println("Did not get the same document back.."); return false; } pdfReader.close(); raw.close(); socket.close(); } catch (IOException e) { System.err.println("testPDF.length=" + testPDF.length + "," + e.getMessage()); //e.printStackTrace(); return false; } return true; }
From source file:com.bleum.canton.loadpage.LoadPage.java
private void logIp(String urlStr, PrintWriter writer) { URL url;/*from ww w. j a v a 2 s. c om*/ InetAddress address = null; try { url = new URL(urlStr); String host = url.getHost(); address = InetAddress.getByName(host); String ip = address.getHostAddress(); LOGGER.info("Ip address of " + urlStr + " is: " + ip); writer.print(urlStr + CSV_SEPERATOR); writer.print(ip + CSV_SEPERATOR); } catch (UnknownHostException e) { // TODO Auto-generated catch block } catch (MalformedURLException e1) { // TODO Auto-generated catch block } }
From source file:ntpgraphic.LineChart.java
public static void NTPClient(String[] servers, int i) { Properties defaultProps = System.getProperties(); //obtiene las "properties" del sistema defaultProps.put("java.net.preferIPv6Addresses", "true");//mapea el valor true en la variable java.net.preferIPv6Addresses if (servers.length == 0) { System.err.println("Usage: NTPClient <hostname-or-address-list>"); System.exit(1);//from w w w .ja v a 2s . co m } Promedio = 0; Cant = 0; NTPUDPClient client = new NTPUDPClient(); // We want to timeout if a response takes longer than 10 seconds client.setDefaultTimeout(10000); try { client.open(); for (String arg : servers) { System.out.println(); try { InetAddress hostAddr = InetAddress.getByName(arg); System.out.println("> " + hostAddr.getHostName() + "/" + hostAddr.getHostAddress()); TimeInfo info = client.getTime(hostAddr); processResponse(info, i); } catch (IOException ioe) { System.err.println(ioe.toString()); } } } catch (SocketException e) { System.err.println(e.toString()); } client.close(); //System.out.println("\n Pomedio "+(Promedio/Cant)); }
From source file:com.aurel.track.dbase.DatabaseHandler.java
/** * Stop the database server//from w w w. j av a2 s . c om */ public static void stopDbServer() { System.setProperty("derby.drda.startNetworkServer", "true"); databaseIsInitialized = false; if (dbServer == null) { try { dbServer = new NetworkServerControl(InetAddress.getByName("localhost"), 15270, user, password); } catch (Exception e) { LOGGER.error(ExceptionUtils.getStackTrace(e)); } } try { Torque.shutdown(); dbServer.shutdown(); } catch (Exception e) { if (!e.getMessage().contains("Connection refused")) { LOGGER.info("Derby server shutdown failed. Ignoring this, but you should check! " + e.getMessage()); LOGGER.debug("Stack trace: ", e); } } }
From source file:cn.ysu.edu.realtimeshare.librtsp.rtsp.UriParser.java
/** * Configures a Session according to the given URI. * Here are some examples of URIs that can be used to configure a Session: * <ul><li>rtsp://xxx.xxx.xxx.xxx:8086?h264&flash=on</li> * <li>rtsp://xxx.xxx.xxx.xxx:8086?h263&camera=front&flash=on</li> * <li>rtsp://xxx.xxx.xxx.xxx:8086?h264=200-20-320-240</li> * <li>rtsp://xxx.xxx.xxx.xxx:8086?aac</li></ul> * @param uri The URI/*from w w w. j a v a2 s . c om*/ * @throws IllegalStateException * @throws IOException * @return A Session configured according to the URI */ public static Session parse(String uri) throws IllegalStateException, IOException { SessionBuilder builder = SessionBuilder.getInstance().clone(); byte audioApi = 0, videoApi = 0; List<NameValuePair> params = URLEncodedUtils.parse(URI.create(uri), "UTF-8"); if (params.size() > 0) { builder.setAudioEncoder(AUDIO_NONE).setVideoEncoder(VIDEO_NONE); // Those parameters must be parsed first or else they won't necessarily be taken into account for (Iterator<NameValuePair> it = params.iterator(); it.hasNext();) { NameValuePair param = it.next(); // FLASH ON/OFF if (param.getName().equalsIgnoreCase("flash")) { if (param.getValue().equalsIgnoreCase("on")) builder.setFlashEnabled(true); else builder.setFlashEnabled(false); } // CAMERA -> the client can choose between the front facing camera and the back facing camera else if (param.getName().equalsIgnoreCase("camera")) { if (param.getValue().equalsIgnoreCase("back")) builder.setCamera(CameraInfo.CAMERA_FACING_BACK); else if (param.getValue().equalsIgnoreCase("front")) builder.setCamera(CameraInfo.CAMERA_FACING_FRONT); } // MULTICAST -> the stream will be sent to a multicast group // The default mutlicast address is 228.5.6.7, but the client can specify another else if (param.getName().equalsIgnoreCase("multicast")) { if (param.getValue() != null) { try { InetAddress addr = InetAddress.getByName(param.getValue()); if (!addr.isMulticastAddress()) { throw new IllegalStateException("Invalid multicast address !"); } builder.setDestination(param.getValue()); } catch (UnknownHostException e) { throw new IllegalStateException("Invalid multicast address !"); } } else { // Default multicast address builder.setDestination("228.5.6.7"); } } // UNICAST -> the client can use this to specify where he wants the stream to be sent else if (param.getName().equalsIgnoreCase("unicast")) { if (param.getValue() != null) { builder.setDestination(param.getValue()); } } // VIDEOAPI -> can be used to specify what api will be used to encode video (the MediaRecorder API or the MediaCodec API) else if (param.getName().equalsIgnoreCase("videoapi")) { if (param.getValue() != null) { if (param.getValue().equalsIgnoreCase("mr")) { videoApi = MediaStream.MODE_MEDIARECORDER_API; } else if (param.getValue().equalsIgnoreCase("mc")) { videoApi = MediaStream.MODE_MEDIACODEC_API; } } } // AUDIOAPI -> can be used to specify what api will be used to encode audio (the MediaRecorder API or the MediaCodec API) else if (param.getName().equalsIgnoreCase("audioapi")) { if (param.getValue() != null) { if (param.getValue().equalsIgnoreCase("mr")) { audioApi = MediaStream.MODE_MEDIARECORDER_API; } else if (param.getValue().equalsIgnoreCase("mc")) { audioApi = MediaStream.MODE_MEDIACODEC_API; } } } // TTL -> the client can modify the time to live of packets // By default ttl=64 else if (param.getName().equalsIgnoreCase("ttl")) { if (param.getValue() != null) { try { int ttl = Integer.parseInt(param.getValue()); if (ttl < 0) throw new IllegalStateException(); builder.setTimeToLive(ttl); } catch (Exception e) { throw new IllegalStateException("The TTL must be a positive integer !"); } } } // H.264 else if (param.getName().equalsIgnoreCase("h264")) { VideoQuality quality = VideoQuality.parseQuality(param.getValue()); builder.setVideoQuality(quality).setVideoEncoder(VIDEO_H264); } // H.263 else if (param.getName().equalsIgnoreCase("h263")) { VideoQuality quality = VideoQuality.parseQuality(param.getValue()); builder.setVideoQuality(quality).setVideoEncoder(VIDEO_H263); } // AMR else if (param.getName().equalsIgnoreCase("amrnb") || param.getName().equalsIgnoreCase("amr")) { AudioQuality quality = AudioQuality.parseQuality(param.getValue()); builder.setAudioQuality(quality).setAudioEncoder(AUDIO_AMRNB); } // AAC else if (param.getName().equalsIgnoreCase("aac")) { AudioQuality quality = AudioQuality.parseQuality(param.getValue()); builder.setAudioQuality(quality).setAudioEncoder(AUDIO_AAC); } } } if (builder.getVideoEncoder() == VIDEO_NONE && builder.getAudioEncoder() == AUDIO_NONE) { SessionBuilder b = SessionBuilder.getInstance(); builder.setVideoEncoder(b.getVideoEncoder()); builder.setAudioEncoder(b.getAudioEncoder()); } Session session = builder.build(); if (videoApi > 0 && session.getVideoTrack() != null) { session.getVideoTrack().setStreamingMethod(videoApi); } if (audioApi > 0 && session.getAudioTrack() != null) { session.getAudioTrack().setStreamingMethod(audioApi); } return session; }
From source file:net.fenyo.gnetwatch.GenericTools.java
/** * Returns the class A/B/C network address containing an IP address. * @param addr_str IPv4 address./*from www . ja v a2 s.c om*/ * @return String network address. */ static public String getNetFromAddress(final String addr_str) { try { final InetAddress addr; addr = InetAddress.getByName(addr_str); if (Inet6Address.class.isInstance(addr)) { // rfc-4291 return "IPv6 range"; } else if (Inet4Address.class.isInstance(addr)) { byte bytes[] = ((Inet4Address) addr).getAddress(); if (unsignedByteToShort(bytes[0]) < 128) { // class A bytes[1] = 0; bytes[2] = 0; bytes[3] = 0; return InetAddress.getByAddress(bytes).toString().substring(1) + "/8"; } else if (unsignedByteToShort(bytes[0]) < 192) { // class B bytes[2] = 0; bytes[3] = 0; return InetAddress.getByAddress(bytes).toString().substring(1) + "/16"; } else if (unsignedByteToShort(bytes[0]) < 224) { // class C bytes[3] = 0; return InetAddress.getByAddress(bytes).toString().substring(1) + "/24"; } else if (unsignedByteToShort(bytes[0]) < 248) { // class D return "224.0.0.0/4"; } else { // class E return "248.0.0.0/4"; } } else return null; } catch (final UnknownHostException ex) { log.error("Exception (addr_str=" + addr_str + ")", ex); return null; } }
From source file:gov.hhs.fha.nhinc.lift.proxy.properties.imp.ConsumerProxyPropertiesFacadeRI.java
@Override public InetAddress getClientProxyAddress() { try {/*from ww w . j av a 2 s . c o m*/ //only expects connection on the localhost from the file downloader return InetAddress.getByName("localhost"); } catch (UnknownHostException e) { log.error(e.getMessage()); } return null; }
From source file:com.dtstack.jlogstash.distributed.netty.server.NettyRev.java
public void startup() { try {/*ww w . j a v a 2 s . co m*/ bossExecutor = Executors.newCachedThreadPool(); workerExecutor = Executors.newCachedThreadPool(); bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(bossExecutor, workerExecutor)); final NettyServerHandler nettyServerHandler = new NettyServerHandler(); // ?????(Handler) bootstrap.setPipelineFactory(new ChannelPipelineFactory() { @Override public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("decoder", new DelimiterBasedFrameDecoder(Integer.MAX_VALUE, false, true, ChannelBuffers.copiedBuffer(delimiter, Charset.forName(encoding)))); pipeline.addLast("handler", nettyServerHandler); return pipeline; } }); bootstrap.setOption("child.receiveBufferSize", receiveBufferSize); bootstrap.setOption("child.keepAlive", true); // bootstrap.setOption("child.tcpNoDelay", true); bootstrap.bind(new InetSocketAddress(InetAddress.getByName(host), port)); logger.warn("netty server start up success port:{}.", port); } catch (Exception e) { logger.error(e.getMessage()); System.exit(1); } }
From source file:org.jboss.as.test.integration.security.CustomLoginModuleTestCase.java
@Deployment public static WebArchive deployment() { // FIXME hack to get things prepared before the deployment happens try {//from w w w .j a v a 2 s .c o m final ModelControllerClient client = ModelControllerClient.Factory .create(InetAddress.getByName("localhost"), 9999); // create required security domains createSecurityDomains(client); } catch (Exception e) { // ignore } ClassLoader tccl = Thread.currentThread().getContextClassLoader(); URL webxml = tccl.getResource("web-secure.war/web.xml"); WebArchive war = create("custom-login-module.war", SecuredServlet.class, webxml); WebSecurityPasswordBasedBase.printWar(war); return war; }