List of usage examples for java.lang Boolean Boolean
@Deprecated(since = "9") public Boolean(String s)
From source file:ch.unizh.ini.jaer.projects.gesture.vlccontrol.TelnetClientExample.java
/*** * Main for the TelnetClientExample./*www. j av a 2 s . c o m*/ ***/ public static void main(String[] args) throws IOException { FileOutputStream fout = null; if (args.length < 1) { System.err.println("Usage: TelnetClientExample1 <remote-ip> [<remote-port>]"); System.exit(1); } String remoteip = args[0]; int remoteport; if (args.length > 1) { remoteport = (new Integer(args[1])).intValue(); } else { remoteport = 23; } try { fout = new FileOutputStream("spy.log", true); } catch (Exception e) { System.err.println("Exception while opening the spy file: " + e.getMessage()); } tc = new TelnetClient(); TerminalTypeOptionHandler ttopt = new TerminalTypeOptionHandler("VT100", false, false, true, false); EchoOptionHandler echoopt = new EchoOptionHandler(true, false, true, false); SuppressGAOptionHandler gaopt = new SuppressGAOptionHandler(true, true, true, true); try { tc.addOptionHandler(ttopt); tc.addOptionHandler(echoopt); tc.addOptionHandler(gaopt); } catch (InvalidTelnetOptionException e) { System.err.println("Error registering option handlers: " + e.getMessage()); } while (true) { boolean end_loop = false; try { tc.connect(remoteip, remoteport); Thread reader = new Thread(new TelnetClientExample()); tc.registerNotifHandler(new TelnetClientExample()); System.out.println("TelnetClientExample"); System.out.println("Type AYT to send an AYT telnet command"); System.out.println("Type OPT to print a report of status of options (0-24)"); System.out.println("Type REGISTER to register a new SimpleOptionHandler"); System.out.println("Type UNREGISTER to unregister an OptionHandler"); System.out.println("Type SPY to register the spy (connect to port 3333 to spy)"); System.out.println("Type UNSPY to stop spying the connection"); reader.start(); OutputStream outstr = tc.getOutputStream(); byte[] buff = new byte[1024]; int ret_read = 0; do { try { ret_read = System.in.read(buff); if (ret_read > 0) { if ((new String(buff, 0, ret_read)).startsWith("AYT")) { try { System.out.println("Sending AYT"); System.out.println("AYT response:" + tc.sendAYT(5000)); } catch (Exception e) { System.err.println("Exception waiting AYT response: " + e.getMessage()); } } else if ((new String(buff, 0, ret_read)).startsWith("OPT")) { System.out.println("Status of options:"); for (int ii = 0; ii < 25; ii++) { System.out.println("Local Option " + ii + ":" + tc.getLocalOptionState(ii) + " Remote Option " + ii + ":" + tc.getRemoteOptionState(ii)); } } else if ((new String(buff, 0, ret_read)).startsWith("REGISTER")) { StringTokenizer st = new StringTokenizer(new String(buff)); try { st.nextToken(); int opcode = (new Integer(st.nextToken())).intValue(); boolean initlocal = (new Boolean(st.nextToken())).booleanValue(); boolean initremote = (new Boolean(st.nextToken())).booleanValue(); boolean acceptlocal = (new Boolean(st.nextToken())).booleanValue(); boolean acceptremote = (new Boolean(st.nextToken())).booleanValue(); SimpleOptionHandler opthand = new SimpleOptionHandler(opcode, initlocal, initremote, acceptlocal, acceptremote); tc.addOptionHandler(opthand); } catch (Exception e) { if (e instanceof InvalidTelnetOptionException) { System.err.println("Error registering option: " + e.getMessage()); } else { System.err.println("Invalid REGISTER command."); System.err.println( "Use REGISTER optcode initlocal initremote acceptlocal acceptremote"); System.err.println("(optcode is an integer.)"); System.err.println( "(initlocal, initremote, acceptlocal, acceptremote are boolean)"); } } } else if ((new String(buff, 0, ret_read)).startsWith("UNREGISTER")) { StringTokenizer st = new StringTokenizer(new String(buff)); try { st.nextToken(); int opcode = (new Integer(st.nextToken())).intValue(); tc.deleteOptionHandler(opcode); } catch (Exception e) { if (e instanceof InvalidTelnetOptionException) { System.err.println("Error unregistering option: " + e.getMessage()); } else { System.err.println("Invalid UNREGISTER command."); System.err.println("Use UNREGISTER optcode"); System.err.println("(optcode is an integer)"); } } } else if ((new String(buff, 0, ret_read)).startsWith("SPY")) { try { tc.registerSpyStream(fout); } catch (Exception e) { System.err.println("Error registering the spy"); } } else if ((new String(buff, 0, ret_read)).startsWith("UNSPY")) { tc.stopSpyStream(); } else { try { outstr.write(buff, 0, ret_read); outstr.flush(); } catch (Exception e) { end_loop = true; } } } } catch (Exception e) { System.err.println("Exception while reading keyboard:" + e.getMessage()); end_loop = true; } } while ((ret_read > 0) && (end_loop == false)); try { tc.disconnect(); } catch (Exception e) { System.err.println("Exception while connecting:" + e.getMessage()); } } catch (Exception e) { System.err.println("Exception while connecting:" + e.getMessage()); System.exit(1); } } }
From source file:Main.java
public static boolean getBooleanAttribute(Element el, String name) { String s = el.getAttribute(name); if (s == null || "0".equals(s)) { return false; }//from ww w . ja v a2 s . c om if ("1".equals(s)) { return true; } return new Boolean(s).booleanValue(); }
From source file:Main.java
public static Object wrapperClassCloner(Object value) { if (value instanceof Double) return new Double(((Double) value).doubleValue()); else if (value instanceof Float) return new Float(((Float) value).floatValue()); else if (value instanceof Long) return new Long(((Long) value).longValue()); else if (value instanceof Boolean) return new Boolean(((Boolean) value).booleanValue()); else if (value instanceof Integer) return new Integer(((Integer) value).intValue()); else// w w w . ja v a 2 s. c o m return null; }
From source file:Main.java
public static void staticMethod() { // Creates an Integer object from an int Integer intObj1 = new Integer(100); // Creates an Integer object from a String Integer intObj2 = new Integer("1969"); // Creates a Double object from a double Double doubleObj1 = new Double(10.45); // Creates a Double object from a String Double doubleObj2 = new Double("234.60"); // Creates a Character object from a char Character charObj1 = new Character('A'); // Creates a Boolean object from a boolean Boolean booleanObj1 = new Boolean(true); // Creates Boolean objects from Strings Boolean booleanTrue = new Boolean("true"); Boolean booleanFalse = new Boolean("false"); }
From source file:Main.java
public static synchronized DocumentBuilder getJaxpDocBuilderNNS() throws ParserConfigurationException { try {/*from w w w . j a v a 2s.co m*/ System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); System.setProperty("javax.xml.parsers.SaxParserFactory", "org.apache.xerces.jaxp.SAXParserFactoryImpl"); DocumentBuilderFactory docBuildFactory = DocumentBuilderFactory.newInstance(); docBuildFactory.setAttribute("http://apache.org/xml/features/dom/defer-node-expansion", new Boolean(false)); docBuildFactory.setNamespaceAware(false); docBuildFactory.setValidating(false); return docBuildFactory.newDocumentBuilder(); } catch (ParserConfigurationException pce) { throw new RuntimeException(pce.getMessage()); } }
From source file:Main.java
/** * Returns true if at least one Accelerometer sensor is available *///from w w w . j a v a 2 s .c o m public static boolean isSupported() { //Log.v(AccelerometerUtils.class.getClass().getCanonicalName(), "isSupported Accelerometer "+supported+" "+oContext); if (supported == null) { if (oContext != null) { sensorManager = (SensorManager) oContext.getSystemService(Context.SENSOR_SERVICE); List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER); supported = new Boolean(sensors.size() > 0); } else { supported = Boolean.FALSE; } } return supported; }
From source file:Main.java
/** * Convert a bean to XML format using JAXB. * //from w ww.j a v a2 s . c o m * @param bean * The bean to marshal as XML. * @param bc * Additional classes to register on the JAXB context for * marshalling. * @return An XML representation of the bean. */ public static <T> String marshal(T bean, Class<?>... bc) { assert bean != null; Class<?>[] bind; if (bc.length > 0) { bind = new Class<?>[bc.length + 1]; bind[0] = bean.getClass(); for (int i = 0; i < bc.length; i++) bind[i + 1] = bc[i]; } else bind = new Class<?>[] { bean.getClass(), }; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { JAXBContext jaxbContext = JAXBContext.newInstance(bind); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, new Boolean(true)); marshaller.marshal(bean, baos); } catch (JAXBException e) { throw new IllegalStateException("Error marshalling", e); } return new String(baos.toByteArray()); }
From source file:Main.java
/** * Searches the node for content of type Long. If non-long content is found, * it logs a warning and returns null.// www . ja v a 2 s .c o m */ public static Boolean extractBooleanFromElement(Node element) { String value = extractStringFromElement(element); return (value == null) ? null : new Boolean(value); }
From source file:net.sf.packtag.util.SafeLogger.java
/** Returns true if the classes from the Apache Log4j library is available */ protected static boolean isLog4jAvailable() { if (log4jAvailable == null) { synchronized (SafeLogger.class) { if (log4jAvailable == null) { try { log4jAvailable = new Boolean(Class.forName("org.apache.log4j.Logger") != null); } catch (ClassNotFoundException e) { log4jAvailable = Boolean.FALSE; }/*from w w w .j a v a2s . c o m*/ } } } return log4jAvailable.booleanValue(); }
From source file:Main.java
/** * Returns the Boolean value of the unqualified attribute with the given * local name belonging to the given element, or null if the attribute is * not present.//from w w w . j a va2 s . c o m * * @param elem an element * @param localName an unqualified attribute name * @return the Boolean value of the attribute, or null if the attribute is * not present */ public static Boolean getAttrBoolean(Element elem, String localName) { String str = getAttrString(elem, localName); if (str != null) { // valid XML Schema boolean values are 0, 1, false, true return new Boolean(str.equals("true") || str.equals("1")); } else { return null; } }