List of usage examples for java.lang System err
PrintStream err
To view the source code for java.lang System err.
Click Source Link
From source file:MainClass.java
public static void main(String[] a) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); String input[] = { "2013-10-01 Vancouver, B.C.", "1248-03-01 Ottawa, ON", "1323-06-06 Toronto, ON" }; for (int i = 0; i < input.length; i++) { ParsePosition pp = new ParsePosition(0); Date d = formatter.parse(input[i], pp); if (d == null) { System.err.println("Invalid date in " + input[i]); continue; }/* ww w . j a v a 2 s. c o m*/ String location = input[i].substring(pp.getIndex()); System.out.println(" on " + d + " in " + location); } }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame("EditorPane Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); try {//w w w . j a v a 2 s . c o m JEditorPane editorPane = new JEditorPane("http://www.java2s.com"); editorPane.setEditable(false); AccessibleContext context = editorPane.getAccessibleContext(); JScrollPane scrollPane = new JScrollPane(editorPane); frame.add(scrollPane); } catch (IOException e) { System.err.println("Unable to load: " + e); } frame.setSize(640, 480); frame.setVisible(true); }
From source file:LINECAPROUNDPDF.java
public static void main(String[] args) { Document document = new Document(); try {//from w w w . j a va2 s .c o m PdfWriter.getInstance(document, new FileOutputStream("LINECAPROUNDPDF.pdf")); document.open(); Chunk chunk; chunk = new Chunk("Multiple lines"); chunk.setUnderline(new Color(0xFF, 0x00, 0x00), 0.0f, 0.3f, 0.0f, 0.4f, PdfContentByte.LINE_CAP_ROUND); document.add(chunk); } catch (Exception ioe) { System.err.println(ioe.getMessage()); } document.close(); }
From source file:EOF.java
public static void main(String args[]) { DataInputStream is = null;//from w ww . j av a 2s . c o m byte ch; try { is = new DataInputStream(new FileInputStream("EOF.java")); while (true) { // exception deals catches EOF ch = is.readByte(); System.out.print((char) ch); System.out.flush(); } } catch (EOFException eof) { System.out.println(" >> Normal program termination."); } catch (FileNotFoundException noFile) { System.err.println("File not found! " + noFile); } catch (IOException io) { System.err.println("I/O error occurred: " + io); } catch (Throwable anything) { System.err.println("Abnormal exception caught !: " + anything); } finally { if (is != null) { try { is.close(); } catch (IOException ignored) { } } } }
From source file:GetCookiePrintAndSetValue.java
public static void main(String args[]) throws Exception { HttpClient client = new HttpClient(); client.getParams().setParameter("http.useragent", "My Browser"); GetMethod method = new GetMethod("http://localhost:8080/"); try {//from w w w . j a v a2 s . c o m client.executeMethod(method); Cookie[] cookies = client.getState().getCookies(); for (int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; System.err.println("Cookie: " + cookie.getName() + ", Value: " + cookie.getValue() + ", IsPersistent?: " + cookie.isPersistent() + ", Expiry Date: " + cookie.getExpiryDate() + ", Comment: " + cookie.getComment()); cookie.setValue("My own value"); } client.executeMethod(method); } catch (Exception e) { System.err.println(e); } finally { method.releaseConnection(); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { int port = 1919; SocketAddress address = new InetSocketAddress("127.0.0.1", port); SocketChannel client = SocketChannel.open(address); ByteBuffer buffer = ByteBuffer.allocate(4); IntBuffer view = buffer.asIntBuffer(); for (int expected = 0;; expected++) { client.read(buffer);// w w w . ja va 2 s . co m int actual = view.get(); buffer.clear(); view.rewind(); if (actual != expected) { System.err.println("Expected " + expected + "; was " + actual); break; } System.out.println(actual); } }
From source file:MainClass.java
public static void main(String[] args) { String hostname = "time.nist.gov"; try {/*from w w w. j ava 2 s .co m*/ Socket theSocket = new Socket(hostname, 13); InputStream timeStream = theSocket.getInputStream(); StringBuffer time = new StringBuffer(); int c; while ((c = timeStream.read()) != -1) time.append((char) c); String timeString = time.toString().trim(); System.out.println("It is " + timeString + " at " + hostname); } // end try catch (UnknownHostException ex) { System.err.println(ex); } catch (IOException ex) { System.err.println(ex); } }
From source file:Main.java
public static void main(String[] args) { Path basedir = FileSystems.getDefault().getPath("C:/tutorial/tmp"); String tmp_file_prefix = "Swing_"; String tmp_file_sufix = ".txt"; //get the default temporary folders path String default_tmp = System.getProperty("java.io.tmpdir"); System.out.println(default_tmp); try {//w ww . jav a 2s. c o m //set a prefix and a sufix Path tmp_2 = Files.createTempFile(tmp_file_prefix, tmp_file_sufix); System.out.println("TMP: " + tmp_2.toString()); } catch (IOException e) { System.err.println(e); } }
From source file:cn.lynx.emi.license.GenerateLicense.java
public static void main(String[] args) throws ClassNotFoundException, ParseException { if (args == null || args.length != 4) { System.err.println("Please provide [machine code] [cpu] [memory in gb] [yyyy-MM-dd] as parameter"); return;/*from w ww .ja va2 s.c o m*/ } InputStream is = GenerateLicense.class.getResourceAsStream("/privatekey"); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String key = null; try { key = br.readLine(); } catch (IOException e) { System.err.println( "Can't read the private key file, make sure there's a file named \"privatekey\" in the root classpath"); e.printStackTrace(); return; } if (key == null) { System.err.println( "Can't read the private key file, make sure there's a file named \"privatekey\" in the root classpath"); return; } String machineCode = args[0]; int cpu = Integer.parseInt(args[1]); long mem = Long.parseLong(args[2]) * 1024 * 1024 * 1024; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); long expDate = sdf.parse(args[3]).getTime(); LicenseBean lb = new LicenseBean(); lb.setCpuCount(cpu); lb.setMemCount(mem); lb.setMachineCode(machineCode); lb.setExpireDate(expDate); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream os = new ObjectOutputStream(baos); os.writeObject(lb); os.close(); String serializedLicense = Base64.encodeBase64String(baos.toByteArray()); System.out.println("License:" + encrypt(key, serializedLicense)); } catch (IOException e) { e.printStackTrace(); } }
From source file:MulticastSniffer.java
public static void main(String[] args) { InetAddress ia = null;/*from w w w .j a va 2 s . c o m*/ byte[] buffer = new byte[65509]; DatagramPacket dp = new DatagramPacket(buffer, buffer.length); int port = 0; try { try { ia = InetAddress.getByName(args[0]); } catch (UnknownHostException e) { // } port = Integer.parseInt(args[1]); } // end try catch (Exception e) { System.err.println(e); System.err.println("Usage: java MulticastSniffer MulticastAddress port"); System.exit(1); } try { MulticastSocket ms = new MulticastSocket(port); ms.joinGroup(ia); while (true) { ms.receive(dp); String s = new String(dp.getData(), 0, 0, dp.getLength()); System.out.println(s); } } catch (SocketException se) { System.err.println(se); } catch (IOException ie) { System.err.println(ie); } }