Java address to string

Java Email InternetAddress parse(String addresslist)

Java Email InternetAddress parse(String addresslist) Parse the given comma separated sequence of addresses into InternetAddress objects.

Introduction

Parse the given comma separated sequence of addresses into InternetAddress objects. Addresses must follow RFC822 syntax.

Syntax

The method parse() from InternetAddress is declared as:

public static InternetAddress[] parse(String addresslist) throws AddressException 

The method parse() has the following parameter:

The method parse() returns array of InternetAddress objects

Example

The following code shows how to use InternetAddress from javax.mail.internet.

Specifically, the code shows you how to use Java Email InternetAddress parse(String addresslist)

import javax.mail.Message; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import java.util.Properties; /**// w w w . d e m o 2 s . c o m * A small java class that composes and sends a test email. */ public class EmailTest < public static void main(String[] args) throws Exception < Properties props = new Properties(); props.put("mail.smtp.auth", "false"); props.put("mail.smtp.starttls.enable", "false"); props.put("mail.smtp.host", "localhost"); props.put("mail.smtp.port", "2500"); Session session = Session.getInstance(props); Message message = new MimeMessage(session); message.setFrom(new InternetAddress("nick@gerakines.net")); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("carolyn@gerakines.net")); message.setSubject("Love"); message.setText("Can't wait to be home! -- nkg"); Transport.send(message); > >
import javax.mail.*; import javax.mail.internet.*; import java.util.Properties; import java.util.Date; public class MailSample < public static void main(String[] args) < try // w w w . d e m o2 s . c om Properties props = new Properties(); props.put("mail.smtp.host", "127.0.0.1"); Session session = Session.getDefaultInstance(props); // session.setDebug(true); MimeMessage mime = new MimeMessage(session); mime.addFrom(InternetAddress.parse("murayama333@gmail.com")); mime.setRecipients(Message.RecipientType.TO, InternetAddress.parse("murayama@kronos-jp.net")); mime.setSubject("My Subject", "iso-2022-jp"); mime.setText("My Text", "iso-2022-jp"); mime.setSentDate(new Date()); Transport.send(mime); > catch (Exception ex) < ex.printStackTrace(); >System.out.println("Hello Mail"); > >
import javax.mail.Message; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class EmailTOMultipleRecipients < public static void main(String[] args) < sendToAll("this is bulk email to all.", "firstRecipient@gmail.com,secondRecipient@gmail.com"); >// w w w . d em o2 s . c o m public static void sendToAll(String subject, String to) < try < MimeMessage message = new MimeMessage(SmtpConifgururation.configure()); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to)); message.setSubject(subject); message.setText("hello..\n you are selected in interview."); Transport.send(message); System.out.println("mail send to all Recipients"); > catch (Exception e) < e.printStackTrace(); >> >

  • Java InternetAddress mergeAddresses(List. in)
  • Java Email InternetAddress tutorial with examples
  • Java Email InternetAddress InternetAddress(String address)
  • Java Email InternetAddress parse(String addresslist)
  • Java Email InternetAddress InternetAddress(String address, boolean strict)
  • Java Email InternetAddress InternetAddress(String address, String personal)
  • Java Email InternetAddress parse(String addresslist, boolean strict)

demo2s.com | Email: | Demo Source and Support. All rights reserved.

Источник

Java InetAddress toString() Converts this IP address to a String.

Converts this IP address to a String. The string returned is of the form: hostname / literal IP address. If the host name is unresolved, no reverse name service lookup is performed. The hostname part will be represented by an empty string.

Syntax

The method toString() from InetAddress is declared as:

public String toString() 

The method toString() returns a string representation of this IP address.

Example

The following code shows how to use InetAddress from java.net.

Specifically, the code shows you how to use Java InetAddress toString()

import java.net.InetAddress; import java.net.UnknownHostException; public class TestGetLocalHost < public static void main(String[] args) < try < InetAddress localhost = InetAddress.getLocalHost(); System.out.println("localhost Unable to set localhost. This prevents creation of a GUID. Cause was: " + e.getMessage()); > > >
import java.net.InetAddress; public class IPDemo < public static void main(String[] args) throws Exception < InetAddress address = InetAddress.getLocalHost(); System.out.println(address.toString()); System.out.println(address); System.out.println(address.getHostName()); InetAddress i = InetAddress.getByName("192.168.1.109"); print(i);/* w w w. d e m o 2s . c o m*/ InetAddress[] baidu = InetAddress.getAllByName("www.baidu.com"); System.out.println(baidu); for (InetAddress inetAddress : baidu) < print(inetAddress); >> private static void print(InetAddress i) < System.out.println(i + "\t" + i.getHostName()); > >
import java.util.Scanner; import java.net.*; public class HostLookup < /**// w w w . d e m o 2 s . co m * @param args */ static Scanner sc = new Scanner(System.in); public static void main(String[] args) < // TODO Auto-generated method stub System.out.println("welcome to ip lookup application"); String host; do < System.out.println("Enter a host name :"); host = sc.nextLine(); try < InetAddress[] addresses = InetAddress.getAllByName(host); for (InetAddress ip : addresses) System.out.println(ip.toString()); > catch (UnknownHostException e) < System.out.println("Unknown host"); > > while (doAgain()); > private static boolean doAgain() < System.out.println(); String s; while (true) < System.out.println("another lookup? (Y or N)"); s = sc.nextLine(); if (s.equalsIgnoreCase("y")) return (true); else if (s.equalsIgnoreCase("n")) return (false); > > >
import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.util.Enumeration; /**// w w w . d e mo 2 s . co m * * @author Legeay Erwann, Etourneau Florian * @version 1.0 * * Cette classe permet l'affichage d'informations concernant les interfaces * de la machine. */ public class AfficheInterfaces < /** * @param args */ public static void main(String[] args) < // TODO Auto-generated method stub String result = ""; try < EnumerationNetworkInterface> enum_net = NetworkInterface.getNetworkInterfaces(); while (enum_net.hasMoreElements()) < NetworkInterface ni = enum_net.nextElement(); result += ni.getName() + ":\n"; EnumerationInetAddress> enum_inet = ni.getInetAddresses(); while (enum_inet.hasMoreElements()) < InetAddress ip = enum_inet.nextElement(); result += "->" + ip.toString() + "\n"; > > > catch (SocketException e) < // TODO Auto-generated catch block //e.printStackTrace(); System.out.println("Erreur lors de la r__cup__ration des interfaces de la machine"); > result = result.equals("") ? "Erreur lors de la r__cup__ration des informations" : result; System.out.println(result); > >
import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.*; import java.net.*; import java.util.ArrayList; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class UDPServer < ArrayList clientList = new ArrayList();; DatagramSocket ds;// w w w . de m o2 s. c o m public static void main(String[] args) < UDPServer u1 = new UDPServer(); u1.openSocket(); while (true) < u1.getClient(); u1.getArrayList(); >> public void getClient() < try < byte[] buf = new byte[1024]; DatagramPacket dp = new DatagramPacket(buf, buf.length); ds.receive(dp); int clientport = dp.getPort(); InetAddress clientAddress = dp.getAddress(); String message = new String(buf, 0, dp.getLength()); int a = 0; for (int i = 0; i < clientList.size(); i++) < if ((clientList.get(i).toString().trim()).equals(clientAddress.toString().trim())) a = 1; > > if (a != 1) < clientList.add(clientAddress); clientList.add(message); >String list = ""; for (int i = 0; i < clientList.size(); i++) < list = list + clientList.get(i); list += ";"; > byte[] listBuf = list.getBytes(); DatagramPacket packet = new DatagramPacket(listBuf, listBuf.length, clientAddress, clientport); ds.send(packet); > catch (SocketException e) < e.printStackTrace(); >catch (IOException e) < e.printStackTrace(); >> public void openSocket() < try < ds = new DatagramSocket(8000); > catch (SocketException e) < e.printStackTrace(); >catch (IOException e) < e.printStackTrace(); >> public void getArrayList() < for (int i = 0; i < clientList.size(); i++) < System.out.println(clientList.get(i)); > > >
import java.io.IOException; import java.net.InetAddress; import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; /**// w w w . d e m o 2 s . c o m * Simple serializer for . Main complexity is * with registration, since same serializer is to be used for sub-classes. */ @SuppressWarnings("serial") public class InetAddressSerializer extends StdScalarSerializerInetAddress> < public InetAddressSerializer() < super(InetAddress.class); > @Override public void serialize(InetAddress value, JsonGenerator jgen, SerializerProvider provider) throws IOException < // Ok: get textual description; choose "more specific" part String str = value.toString().trim(); int ix = str.indexOf('/'); if (ix >= 0) < if (ix == 0) < // missing host name; use address str = str.substring(1); > else < // otherwise use name str = str.substring(0, ix); > > jgen.writeString(str); > @Override public void serializeWithType(InetAddress value, JsonGenerator jgen, SerializerProvider provider, TypeSerializer typeSer) throws IOException, JsonGenerationException < // Better ensure we don't use specific sub-classes. typeSer.writeTypePrefixForScalar(value, jgen, InetAddress.class); serialize(value, jgen, provider); typeSer.writeTypeSuffixForScalar(value, jgen); > >

  • Java InetAddress isLinkLocalAddress() Utility routine to check if the InetAddress is an link local address.
  • Java InetAddress isSiteLocalAddress() Utility routine to check if the InetAddress is a site local address.
  • Java InetAddress isMulticastAddress() Utility routine to check if the InetAddress is an IP multicast address.
  • Java InetAddress toString() Converts this IP address to a String.
  • Java InetAddress getAllByName(String host) Given the name of a host, returns an array of its IP addresses, based on the configured name service on .
  • Java InetAddress isAnyLocalAddress() Utility routine to check if the InetAddress is a wildcard address.
  • Java InetAddress getByAddress(String host, byte[] addr) Creates an InetAddress based on the provided host name and IP address.

demo2s.com | Email: | Demo Source and Support. All rights reserved.

Источник

Java address to string

Learn Latest Tutorials

Splunk tutorial

SPSS tutorial

Swagger tutorial

T-SQL tutorial

Tumblr tutorial

React tutorial

Regex tutorial

Reinforcement learning tutorial

R Programming tutorial

RxJS tutorial

React Native tutorial

Python Design Patterns

Python Pillow tutorial

Python Turtle tutorial

Keras tutorial

Preparation

Aptitude

Logical Reasoning

Verbal Ability

Company Interview Questions

Artificial Intelligence

AWS Tutorial

Selenium tutorial

Cloud Computing

Hadoop tutorial

ReactJS Tutorial

Data Science Tutorial

Angular 7 Tutorial

Blockchain Tutorial

Git Tutorial

Machine Learning Tutorial

DevOps Tutorial

B.Tech / MCA

DBMS tutorial

Data Structures tutorial

DAA tutorial

Operating System

Computer Network tutorial

Compiler Design tutorial

Computer Organization and Architecture

Discrete Mathematics Tutorial

Ethical Hacking

Computer Graphics Tutorial

Software Engineering

html tutorial

Cyber Security tutorial

Automata Tutorial

C Language tutorial

C++ tutorial

Java tutorial

.Net Framework tutorial

Python tutorial

List of Programs

Control Systems tutorial

Data Mining Tutorial

Data Warehouse Tutorial

Javatpoint Services

JavaTpoint offers too many high quality services. Mail us on h[email protected], to get more information about given services.

  • Website Designing
  • Website Development
  • Java Development
  • PHP Development
  • WordPress
  • Graphic Designing
  • Logo
  • Digital Marketing
  • On Page and Off Page SEO
  • PPC
  • Content Development
  • Corporate Training
  • Classroom and Online Training
  • Data Entry

Training For College Campus

JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected].
Duration: 1 week to 2 week

Like/Subscribe us for latest updates or newsletter RSS Feed Subscribe to Get Email Alerts Facebook Page Twitter Page YouTube Blog Page

Источник

How do I convert raw IP address to String?

This example show you how to convert a raw IP address, an array of byte , returned by InetAddress.getAddress() method call to its string representation.

package org.kodejava.net; import java.net.InetAddress; import java.net.UnknownHostException; public class RawIPToString < public static void main(String[] args) < byte[] ip = new byte[0]; try < InetAddress address = InetAddress.getLocalHost(); ip = address.getAddress(); >catch (UnknownHostException e) < e.printStackTrace(); >String ipAddress = RawIPToString.getIpAddress(ip); System.out.println("IP Address = " + ipAddress); try < InetAddress address = InetAddress.getByName("google.com"); ip = address.getAddress(); >catch (UnknownHostException e) < e.printStackTrace(); >ipAddress = RawIPToString.getIpAddress(ip); System.out.println("IP Address = " + ipAddress); > /** * Convert raw IP address to string. * * @param rawBytes raw IP address. * @return a string representation of the raw ip address. */ private static String getIpAddress(byte[] rawBytes) < int i = 4; StringBuilder ipAddress = new StringBuilder(); for (byte raw : rawBytes) < ipAddress.append(raw & 0xFF); if (--i >0) < ipAddress.append("."); >> return ipAddress.toString(); > > 

This example will print something like:

IP Address = 30.30.30.60 IP Address = 142.251.10.113 

A programmer, recreational runner and diver, live in the island of Bali, Indonesia. Programming in Java, Spring, Hibernate / JPA. You can support me working on this project, buy me a cup of coffee ☕ every little bit helps, thank you 🙏

Источник

Читайте также:  Ubuntu server установка apache php mysql
Оцените статью