List of usage examples for java.net InetAddress getLocalHost
public static InetAddress getLocalHost() throws UnknownHostException
From source file:com.sudoku.data.model.User.java
public User(String pseudo, String brutPassword, Date birthDate, String profilePicturePath) throws NoSuchAlgorithmException, UnsupportedEncodingException, UnknownHostException { MessageDigest mDigest = MessageDigest.getInstance("SHA-256"); Calendar cal = new GregorianCalendar(); this.pseudo = pseudo; this.salt = this.randomSalt(); String toBeHashed = brutPassword + this.getSalt(); String hashed = new String(Base64.encode(mDigest.digest(toBeHashed.getBytes("UTF-8")))); this.password = hashed; this.birthDate = birthDate; this.profilePicturePath = profilePicturePath; this.createDate = cal.getTime(); this.updateDate = this.createDate; this.ipAddress = InetAddress.getLocalHost().getHostAddress(); this.contactCategories = new LinkedList<>(); System.out.println(this.getPassword()); }
From source file:com.appeligo.search.actions.ResponseReportAction.java
public String execute() throws Exception { long timestamp = new Date().getTime(); String day = Utils.getDatePath(timestamp); String hostname = null;/* www.j a v a 2 s . c o m*/ try { hostname = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { hostname = "UnknownHost"; } String dirname = documentRoot + "/stats/" + day + "/" + hostname; String responseFileName = dirname + "/response-" + reporter + ".html"; try { File dir = new File(dirname); if ((!dir.exists()) && (!dir.mkdirs())) { throw new IOException("Error creating directory " + dirname); } File file = new File(responseFileName); PrintStream responseFile = null; if (file.exists()) { responseFile = new PrintStream(new FileOutputStream(responseFileName, true)); } else { responseFile = new PrintStream(new FileOutputStream(responseFileName)); String title = "Response Times for " + getServletRequest().getServerName() + " to " + reporter; responseFile.println("<html><head><title>" + title + "</title></head>"); responseFile.println("<body><h1>" + title + "</h1>"); responseFile.println("<table border='1'>"); responseFile.println("<tr>"); responseFile.println("<th>Time (UTC)</th>"); responseFile.println("<th>Response (Millis)</th>"); responseFile.println("<th>Status</th>"); responseFile.println("<th>Bytes Read</th>"); responseFile.println("<th>Timed Out</th>"); responseFile.println("<th>Exception</th>"); responseFile.println("</tr>"); } Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("GMT")); cal.setTimeInMillis(timestamp); String time = String.format("%1$tH:%1$tM:%1$tS", cal); responseFile.print("<tr>"); responseFile.print("<td>" + time + "</td>"); responseFile.format("<td>%,d</td>", responseMillis); responseFile.print("<td>" + status + "</td>"); responseFile.format("<td>%,d</td>", bytesRead); responseFile.print("<td>" + timedOut + "</td>"); responseFile.print("<td>" + exception + "</td>"); responseFile.println("</tr>"); } catch (IOException e) { log.error("Error opening or writing to " + responseFileName, e); } return SUCCESS; }
From source file:io.fabric8.insight.log.support.LogQuerySupport.java
protected LogQuerySupport() { try {//from w w w . j av a2s . c om hostName = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { LOG.warn("Failed to get host name: " + e, e); } }
From source file:com.inmobi.conduit.zookeeper.CuratorLeaderManager.java
private void connect() throws Exception { client.start();// connect to ZK LOG.info("becomeLeader :: connect to ZK [" + zkConnectString + "]"); leaderSelector.setId(InetAddress.getLocalHost().getHostName()); leaderSelector.start();//w ww .j a va2 s. c o m LOG.info("started the LeaderSelector"); }
From source file:hd3gtv.mydmam.db.orm.AutotestOrm.java
public static AutotestOrm populate(int index) { AutotestOrm result = new AutotestOrm(); result.key = "THISISMYKEY" + String.valueOf(index); result.strvalue = "Hello world with cnts"; result.bytvalue = result.strvalue.toUpperCase().getBytes(); result.intvalue = 42;// w ww. j a v a 2 s . co m result.lngvalue = -3329447494103907027L; result.bolvalue = true; result.fltvalue = 6.55957f; result.dlbvalue = (double) result.lngvalue / 11d; result.uuivalue = UUID.fromString("110E8400-E29B-11D4-A716-446655440000"); result.jsovalue = new JSONObject(); result.jsovalue.put("Hello", "world"); result.jsovalue.put("Count", index); result.jsavalue = new JSONArray(); result.jsavalue.add("One"); result.jsavalue.add(42); result.jsavalue.add("Un"); try { result.addressvalue = InetAddress.getLocalHost(); } catch (UnknownHostException e) { e.printStackTrace(); } result.sbuvalue = new StringBuffer(); result.sbuvalue.append(result.key); result.sbuvalue.append(result.strvalue); result.sbuvalue.append(result.lngvalue); result.calendarvalue = Calendar.getInstance(); result.calendarvalue.set(1995, 05, 23, 10, 04, 8); result.calendarvalue.set(Calendar.MILLISECOND, 666); result.dtevalue = result.calendarvalue.getTime(); result.strarrayvalue = new String[2]; result.strarrayvalue[0] = result.strvalue; result.strarrayvalue[1] = result.key; result.serializvalue = new HashMap<String, String>(); result.serializvalue.put("Some var", result.strvalue); result.serializvalue.put("Other var", result.uuivalue.toString()); result.enumvalue = MyEnum.ME; result.iamempty = ""; result.iamanindex = index; result.donttouchme = "F*ck you"; return result; }
From source file:net.dfs.user.test.Store.java
public static String userName() throws UnknownHostException { return InetAddress.getLocalHost().getHostName(); }
From source file:com.streamreduce.util.SqsQueueNameFormatter.java
private static String addMachineNameToPrefixIfNeeded(String environmentPrefix) { if ("dev".equals(environmentPrefix.trim())) { String devSpecificPrefix; try {/* w ww.j av a 2s.c o m*/ String hostname = InetAddress.getLocalHost().getHostName(); //everyone gets their own dev queues! devSpecificPrefix = hostname.split("\\.")[0]; //In case hostname is a FQDN } catch (Exception e) { LOGGER.warn("Unable to get hostname for dev machine. Using \"shared\" as a prefix"); devSpecificPrefix = "shared"; } environmentPrefix = environmentPrefix + "-" + devSpecificPrefix; } return environmentPrefix; }
From source file:massbank.svn.SVNUtils.java
/** * //from ww w. j av a2 s .c o m */ public static String getLocalIPAddress() { String address = ""; try { Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces.hasMoreElements()) { NetworkInterface network = interfaces.nextElement(); Enumeration<InetAddress> addresses = network.getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress inet = addresses.nextElement(); if (!inet.isLoopbackAddress() && inet instanceof Inet4Address) { return inet.getHostAddress(); } } } address = InetAddress.getLocalHost().getHostAddress(); } catch (Exception e) { } return address; }
From source file:com.lucid.touchstone.data.LineDocMaker.java
public LineDocMaker(String fileName, StreamProvider stream) { try {/*w w w . j a va 2s . c o m*/ InetAddress addr = InetAddress.getLocalHost(); // Get IP Address ipAddr = addr.getAddress(); this.fileName = fileName; this.streamProvider = stream; open(); } catch (Exception e) { e.printStackTrace(); } }
From source file:net.bioclipse.dbxp.business.DbxpManager.java
public static String getMacAddress() throws SocketException, UnknownHostException { InetAddress ip = InetAddress.getLocalHost(); NetworkInterface network = NetworkInterface.getByInetAddress(ip); byte[] mac = network.getHardwareAddress(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < mac.length; i++) { sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "" : "")); }//from www. ja v a 2 s .c o m //System.out.println(sb.toString()); return sb.toString(); }