Example usage for java.util Iterator next

List of usage examples for java.util Iterator next

Introduction

In this page you can find the example usage for java.util Iterator next.

Prototype

E next();

Source Link

Document

Returns the next element in the iteration.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Selector selector = Selector.open();

    ServerSocketChannel ssChannel1 = ServerSocketChannel.open();
    ssChannel1.configureBlocking(false);
    ssChannel1.socket().bind(new InetSocketAddress(80));

    ServerSocketChannel ssChannel2 = ServerSocketChannel.open();
    ssChannel2.configureBlocking(false);
    ssChannel2.socket().bind(new InetSocketAddress(81));

    ssChannel1.register(selector, SelectionKey.OP_ACCEPT);
    ssChannel2.register(selector, SelectionKey.OP_ACCEPT);

    while (true) {
        selector.select();//from w  w  w .j  ava 2  s .c  o  m
        Iterator it = selector.selectedKeys().iterator();
        while (it.hasNext()) {
            SelectionKey selKey = (SelectionKey) it.next();
            it.remove();

            if (selKey.isAcceptable()) {
                ServerSocketChannel ssChannel = (ServerSocketChannel) selKey.channel();
                SocketChannel sc = ssChannel.accept();
                ByteBuffer buf = ByteBuffer.allocate(100);
                int numBytesRead = sc.read(buf);

                if (numBytesRead == -1) {
                    sc.close();
                } else {
                    // Read the bytes from the buffer
                }
                int numBytesWritten = sc.write(buf);
            }
        }
    }
}

From source file:be.dnsbelgium.rdap.client.ManGenerator.java

public static void main(String[] args) {
    Options options = new RDAPOptions(Locale.ENGLISH);
    Iterator<Option> it = options.getOptions().iterator();
    StringBuilder sb = new StringBuilder();
    while (it.hasNext()) {
        Option option = it.next();
        sb.append(String.format(".IP \"%s\"\n%s\n", getOptionString(option),
                option.getDescription() == null ? "" : option.getDescription()));
    }//from   w  ww . jav a 2  s .c o m
    System.out.println(sb.toString());
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());

    KeyPair pair = generateRSAKeyPair();

    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    bOut.write(generateV1Certificate(pair).getEncoded());
    bOut.close();//from w  w  w  . j a  va2s  .c om

    InputStream in = new ByteArrayInputStream(bOut.toByteArray());

    CertificateFactory fact = CertificateFactory.getInstance("X.509", "BC");

    X509Certificate x509Cert;
    Collection collection = new ArrayList();

    while ((x509Cert = (X509Certificate) fact.generateCertificate(in)) != null) {
        collection.add(x509Cert);
    }

    Iterator it = collection.iterator();
    while (it.hasNext()) {
        System.out.println("version: " + ((X509Certificate) it.next()).getVersion());
    }
}

From source file:Main.java

public static void main(String[] args) {

    ArrayList<String> aList = new ArrayList<String>();

    aList.add("1");
    aList.add("2");
    aList.add("3");
    aList.add("4");
    aList.add("5");

    Iterator itr = aList.iterator();

    // iterate through the ArrayList values using Iterator's hasNext and next methods

    while (itr.hasNext()) {
        System.out.println(itr.next());
    }/*from  ww w  .jav a  2 s.  c o m*/
}

From source file:Main.java

static public void main(String args[]) throws Exception {
    FileInputStream fin = new FileInputStream("a.gif");
    Iterator readers = ImageIO.getImageReadersBySuffix("GIF");
    ImageReader imageReader = (ImageReader) readers.next();
    ImageInputStream iis = ImageIO.createImageInputStream(fin);
    imageReader.setInput(iis, false);/*from   w ww  .  ja  va  2  s.  c  om*/

    imageReader.addIIOReadProgressListener(new IIOReadProgressListener() {
        public void imageComplete(ImageReader source) {
            System.out.println("image complete " + source);
        }

        public void imageProgress(ImageReader source, float percentageDone) {
            System.out.println("image progress " + source + ": " + percentageDone + "%");
        }

        public void imageStarted(ImageReader source, int imageIndex) {
            System.out.println("image #" + imageIndex + " started " + source);
        }

        public void readAborted(ImageReader source) {
            System.out.println("read aborted " + source);
        }

        public void sequenceComplete(ImageReader source) {
            System.out.println("sequence complete " + source);
        }

        public void sequenceStarted(ImageReader source, int minIndex) {
            System.out.println("sequence started " + source + ": " + minIndex);
        }

        public void thumbnailComplete(ImageReader source) {
            System.out.println("thumbnail complete " + source);
        }

        public void thumbnailProgress(ImageReader source, float percentageDone) {
            System.out.println("thumbnail started " + source + ": " + percentageDone + "%");
        }

        public void thumbnailStarted(ImageReader source, int imageIndex, int thumbnailIndex) {
            System.out.println("thumbnail progress " + source + ", " + thumbnailIndex + " of " + imageIndex);
        }
    });

    BufferedImage image = imageReader.read(0);

    Iterator imageWriters = ImageIO.getImageWritersBySuffix("JPG");
    ImageWriter imageWriter = (ImageWriter) imageWriters.next();
    File file = new File("b.JPG");
    ImageOutputStream ios = ImageIO.createImageOutputStream(file);
    imageWriter.setOutput(ios);
    imageWriter.write(image);
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    URL[] urls = { new URL("http://yourserver/small.png") };
    for (URL url : urls) {
        ImageInputStream iis = ImageIO.createImageInputStream(url.openStream());
        Iterator<ImageReader> readers = ImageIO.getImageReaders(iis);

        System.out.println("url= " + url.getPath());
        while (readers.hasNext()) {
            ImageReader read = readers.next();
            System.out.println("format name = " + read.getFormatName());
        }//from  w  w  w. ja  va  2  s  .com
        System.out.println();
    }
}

From source file:Counter.java

public static void main(String[] args) throws FileNotFoundException {
    if (args.length == 0) {
        System.out.println(usage);
        System.exit(1);//from w w  w .j  av  a2  s . c  om
    }
    WordCount1 wc = new WordCount1(args[0]);
    wc.countWords();
    Iterator keys = wc.keySet().iterator();
    while (keys.hasNext()) {
        String key = (String) keys.next();
        System.out.println(key + ": " + wc.getCounter(key).read());
    }
    wc.dispose();
}

From source file:com.camel.trainreserve.TicketReserver.java

public static void main(String[] args) {
    getCaptchaImg();// w  w  w  .j  av  a  2 s  .  c  om

    String filePath = FileUtils.getFileAbsolutePath();
    Properties props = FileUtils.readProperties(filePath + "/trainreserve/checkorderInfo.properties");
    Iterator it = props.keySet().iterator();
    while (it.hasNext()) {
        String key = (String) it.next();
        NameValuePair nvp = new BasicNameValuePair(key, (String) props.get(key));
        datas.add(nvp);
    }
    String formDate = URLEncodedUtils.format(datas, "UTF-8");
    String res = null;
    try {
        res = JDKHttpsClient.doPost(checkOrderUrl, cookieStr, formDate, "UTF-8", 3000, 2000);
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println("response =" + res);
}

From source file:NewFingerServer.java

public static void main(String[] arguments) throws Exception {
    ServerSocketChannel sockChannel = ServerSocketChannel.open();
    sockChannel.configureBlocking(false);

    InetSocketAddress server = new InetSocketAddress("localhost", 79);
    ServerSocket socket = sockChannel.socket();
    socket.bind(server);/*from w ww  . j  a  v a  2 s  .  com*/

    Selector selector = Selector.open();
    sockChannel.register(selector, SelectionKey.OP_ACCEPT);

    while (true) {
        selector.select();
        Set keys = selector.selectedKeys();
        Iterator it = keys.iterator();
        while (it.hasNext()) {
            SelectionKey selKey = (SelectionKey) it.next();
            it.remove();
            if (selKey.isAcceptable()) {
                ServerSocketChannel selChannel = (ServerSocketChannel) selKey.channel();
                ServerSocket selSocket = selChannel.socket();
                Socket connection = selSocket.accept();

                InputStreamReader isr = new InputStreamReader(connection.getInputStream());
                BufferedReader is = new BufferedReader(isr);
                PrintWriter pw = new PrintWriter(new BufferedOutputStream(connection.getOutputStream()), false);
                pw.println("NIO Finger Server");
                pw.flush();
                String outLine = null;
                String inLine = is.readLine();
                if (inLine.length() > 0) {
                    outLine = inLine;
                }
                readPlan(outLine, pw);
                pw.flush();
                pw.close();
                is.close();

                connection.close();
            }
        }
    }
}

From source file:chat.jsonTest.java

/**
 * @param args the command line arguments
 *//*from w w  w . j a  v  a  2s.c o m*/
public static void main(String[] args) throws ParseException, IOException {
    // TODO code application logic here
    JSONParser parser = new JSONParser();
    String fullPath = "userInfo.json";
    //BufferedReader reader = new BufferedReader(new FileReader(fullPath));

    Object obj = parser.parse(new FileReader("userInfo.json"));
    JSONObject jsonObject = (JSONObject) obj;
    /*while ((line = reader.readLine()) != null) {
        System.out.println(line);
    }*/
    JSONArray lang = (JSONArray) jsonObject.get("userInfo");
    Iterator i = lang.iterator();

    // take each value from the json array separately
    while (i.hasNext()) {
        JSONObject innerObj = (JSONObject) i.next();
        System.out
                .println("username " + innerObj.get("username") + " with password " + innerObj.get("password"));
    }

}