List of usage examples for java.lang System getProperty
public static String getProperty(String key)
From source file:FileTableHTML.java
public static void main(String[] args) throws IOException { // Get the name of the directory to display String dirname = (args.length > 0) ? args[0] : System.getProperty("user.home"); // Create something to display it in. final JEditorPane editor = new JEditorPane(); editor.setEditable(false); // we're browsing not editing editor.setContentType("text/html"); // must specify HTML text editor.setText(makeHTMLTable(dirname)); // specify the text to display // Set up the JEditorPane to handle clicks on hyperlinks editor.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent e) { // Handle clicks; ignore mouseovers and other link-related events if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { // Get the HREF of the link and display it. editor.setText(makeHTMLTable(e.getDescription())); }//from ww w. jav a 2 s .c om } }); // Put the JEditorPane in a scrolling window and display it. JFrame frame = new JFrame("FileTableHTML"); frame.getContentPane().add(new JScrollPane(editor)); frame.setSize(650, 500); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(Main.class.getSimpleName()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JTree tree = new JTree(createTreeModel(new File(System.getProperty("user.dir")), true)); tree.setCellRenderer(new DefaultTreeCellRenderer() { @Override// w w w . j av a2 s . co m public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); if (value instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; if (node.getUserObject() instanceof File) { setText(((File) node.getUserObject()).getName()); } } return this; } }); tree.getSelectionModel().addTreeSelectionListener(e -> { Object object = tree.getLastSelectedPathComponent(); if (object instanceof DefaultMutableTreeNode) { Object userObject = ((DefaultMutableTreeNode) object).getUserObject(); if (userObject instanceof File) { File file = (File) userObject; System.out.println( "Selected file" + file.getAbsolutePath() + " Is directory? " + file.isDirectory()); } } }); JScrollPane pane = new JScrollPane(tree); frame.add(pane); frame.setSize(400, 600); frame.setVisible(true); }
From source file:Test.java
public static void main(String[] args) throws IOException { Path path = Paths.get("/users.txt"); try (SeekableByteChannel sbc = Files.newByteChannel(path)) { ByteBuffer buffer = ByteBuffer.allocate(1024); sbc.position(4);/*from w w w .ja va2s . com*/ sbc.read(buffer); for (int i = 0; i < 5; i++) { System.out.print((char) buffer.get(i)); } buffer.clear(); sbc.position(0); sbc.read(buffer); for (int i = 0; i < 4; i++) { System.out.print((char) buffer.get(i)); } sbc.position(0); buffer = ByteBuffer.allocate(1024); String encoding = System.getProperty("file.encoding"); int numberOfBytesRead = sbc.read(buffer); System.out.println("Number of bytes read: " + numberOfBytesRead); while (numberOfBytesRead > 0) { buffer.rewind(); System.out.print("[" + Charset.forName(encoding).decode(buffer) + "]"); buffer.flip(); numberOfBytesRead = sbc.read(buffer); System.out.println("\nNumber of bytes read: " + numberOfBytesRead); } } }
From source file:eu.optimis.ics.p2p.MyFileAlterationObserver.java
public static void main(String[] args) throws Exception { System.out.println("Present Working Directory is : " + System.getProperty("user.dir")); File directory = new File(System.getProperty("user.dir") + "/data"); IOFileFilter files = FileFilterUtils.and(FileFilterUtils.fileFileFilter(), FileFilterUtils.suffixFileFilter(".txt")); FileAlterationObserver observer = new FileAlterationObserver(directory, files); observer.initialize();//from w ww. ja v a 2 s.c o m // Add Listener MyFileAlterationListener listener = new MyFileAlterationListener(); observer.addListener(listener); FileAlterationMonitor monitor = new FileAlterationMonitor(1000, observer); monitor.addObserver(observer); monitor.start(); }
From source file:BufferToText.java
public static void main(String[] args) throws Exception { FileChannel fc = new FileOutputStream("data2.txt").getChannel(); fc.write(ByteBuffer.wrap("Some text".getBytes())); fc.close();/* w ww. ja v a2 s . c o m*/ fc = new FileInputStream("data2.txt").getChannel(); ByteBuffer buff = ByteBuffer.allocate(BSIZE); fc.read(buff); buff.flip(); // Doesn't work: System.out.println(buff.asCharBuffer()); // Decode using this system's default Charset: buff.rewind(); String encoding = System.getProperty("file.encoding"); System.out.println("Decoded using " + encoding + ": " + Charset.forName(encoding).decode(buff)); // Or, we could encode with something that will print: fc = new FileOutputStream("data2.txt").getChannel(); fc.write(ByteBuffer.wrap("Some text".getBytes("UTF-16BE"))); fc.close(); // Now try reading again: fc = new FileInputStream("data2.txt").getChannel(); buff.clear(); fc.read(buff); buff.flip(); System.out.println(buff.asCharBuffer()); // Use a CharBuffer to write through: fc = new FileOutputStream("data2.txt").getChannel(); buff = ByteBuffer.allocate(24); // More than needed buff.asCharBuffer().put("Some text"); fc.write(buff); fc.close(); // Read and display: fc = new FileInputStream("data2.txt").getChannel(); buff.clear(); fc.read(buff); buff.flip(); System.out.println(buff.asCharBuffer()); }
From source file:de.iritgo.aktario.framework.IritgoClient.java
/** * The client main method.//from w ww . j av a2 s. c o m * * @param args The program args. */ public static void main(String[] args) { if (null == System.getProperty("swing.aatext")) { System.setProperty("swing.aatext", "true"); } Options options = new Options(); IritgoEngine.create(IritgoEngine.START_CLIENT, options, args); }
From source file:com.home.ln_spring.ch5.env.EnvironmentSample.java
public static void main(String[] args) { GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); ctx.refresh();//from w ww . j av a 2 s . c o m ConfigurableEnvironment env = ctx.getEnvironment(); MutablePropertySources propertySources = env.getPropertySources(); Map appMap = new HashMap(); appMap.put("user.home", "/home/vitaliy/NetBeansProjects/Ln_Spring"); propertySources.addFirst(new MapPropertySource("SPRING3_MAP", appMap)); System.out.println("user.home: " + System.getProperty("user.home")); System.out.println("JAVA_HOME: " + System.getProperty("JAVA_HOME")); System.out.println("user.home: " + env.getProperty("user.home")); System.out.println("JAVA_HOME: " + env.getProperty("JAVA_HOME")); }
From source file:org.bigtextml.drivers.BigMapReadTest.java
public static void main(String[] args) { /*/*from ww w .j av a 2s . c om*/ ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"InMemoryDataMining.xml"}); */ System.out.println(System.getProperty("InvokedFromSpring")); //Map<String,List<Integer>> bm = context.getBean("bigMapTest",BigMap.class); Map<String, List<Integer>> bm = ManagementServices.getBigMap("tmCache"); System.out.println(((BigMap) bm).getCacheName()); int max = 1000000; String key = Integer.toString(max - 1); //bm.remove(key); for (int i = 0; i < 3; i++) { long millis = System.currentTimeMillis(); System.out.println(bm.get(Integer.toString(500000))); System.out.println(System.currentTimeMillis() - millis); } bm.clear(); }
From source file:org.bigtextml.drivers.BigMapTest.java
public static void main(String[] args) { /*/*www .j av a 2s . com*/ ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"InMemoryDataMining.xml"}); */ System.out.println(System.getProperty("InvokedFromSpring")); //Map<String,List<Integer>> bm = context.getBean("bigMapTest",BigMap.class); Map<String, List<Integer>> bm = ManagementServices.getBigMap("tmCache"); System.out.println(((BigMap) bm).getCacheName()); int max = 1000000; //bm.setMaxCapacity(1000); for (int i = 0; i < max; i++) { List<Integer> x = new ArrayList<Integer>(); for (int j = 0; j < 5; j++) { x.add(j); } x.add(i); bm.put(Integer.toString(i), x); } String key = Integer.toString(max - 1); //bm.remove(key); for (int i = 0; i < 3; i++) { long millis = System.currentTimeMillis(); System.out.println(bm.get(Integer.toString(500000))); System.out.println(System.currentTimeMillis() - millis); } bm.clear(); }
From source file:com.villemos.ispace.Starter.java
public static void main(String[] args) { System.out.println("Starting iSpace."); try {/* ww w . j av a 2 s .co m*/ /** Read the configuration file as the first argument. If not set, then we try the default name. */ String assemblyFile = System.getProperty("ispace.assembly") == null ? "assembly.xml" : System.getProperty("ispace.assembly"); System.out.println("Using assembly file " + assemblyFile); new FileSystemXmlApplicationContext(assemblyFile); while (true) { try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } }