InputStream and LinkedList

Hey all,
I was just wondering about how to allow the InputStream read data to be cast to my LinkedList (java.util.List<DataList>)?
Incompatible types is given for:
datas = (DataList)inStream.readObject()I've tried almost everything and nothing in my Java book says anything about casting collection objects into the reader.
Any help would be greatly appreciated!

If your instance "datas" is a List<DataList> you would need to cast "inStream.readObject()" to (List<DataList>)
This probably will not work though, unless the return method of readObject() is an instance of, or a subclass of, List<DataList>. I couldn't find your InputStream class.
1111PM wrote:casting collection objects into the reader.I don't know exactly your situation but you could try a very basic way of doing this with the List<E> method "add(E e)" [http://download.java.net/jdk7/docs/api/java/util/LinkedList.html#add(E)]
I'm not sure how else to help. I don't know your situation exactly. You need to give more code.

Similar Messages

  • Both of the advantages of ArrayList and LinkedList are needed.

    Hi there,
    I wonder how if I want performance on random access an ArrayList and also remove elements in any position of the List? As far as I know that a LinkedList is the best choice if I want to remove elements in any position of the List, but it's slow on traversing the List. Sometimes it's hard to choose between ArrayList and LinkedList, is there a way that I could have both advantages of ArrayList and LinkedList?
    Any suggestion?
    Thanks,
    Jax

    I think you might be interested in the data structure
    called a deque. It is built for fast insertions
    at both ends and is usually implemented as a linked
    list of arrays. The standard collections API does not
    offer this data structure (I wish it did). So you have
    to find a 3rd party implementation. Try searching
    Google: http://www.google.com/search?q=java+deque
    Thanks nasch and pervel for the information. What do you think if I do something like this?
    List a = new ArrayList();
    // perform some tasks that is fast with ArrayList
    List b = new LinkedList(a);
    // perform some tasks..
    Although a new object is created, but that perform better than one ArrayList or one LinkedList solely.

  • InputStream and BufferedInputStream

    I'm having some trouble reading an InputStream and BufferedInputStream. I want to connection to a server and see what files are in a directory, but I can't break the BIS apart to see what file names are present. I was wondering if I'm going about this wrong.
    What I do is connect to a server,
    Create an InputStream with client.get (ftp protocol)
    Buffer that stream
    But this is where I get stuck, I can buffer and read 1 file at a time, but I can count how many I have. Users will be dumping files in this directory all the time and I want to count them and display a message saying how many there are before I start downloading them. help please

    file class has isFile(), isDirectory()
    list() will list everything in the current directory then loop through to check to see which one is a file and which is a directory
    Here's an example taken from Deitel & Deitel "Java How to program"
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.*;
    public class FileTest extends JFrame
                          implements ActionListener {
       private JTextField enter;
       private JTextArea output;
       public FileTest()
          super( "Testing class File" );
          enter = new JTextField(
             "Enter file or directory name here" );
          enter.addActionListener( this );
          output = new JTextArea();
          Container c = getContentPane();
          ScrollPane p = new ScrollPane();
          p.add( output );
          c.add( enter, BorderLayout.NORTH );
          c.add( p, BorderLayout.CENTER );
          setSize( 400, 400 );
          show();
       public void actionPerformed( ActionEvent e )
          File name = new File( e.getActionCommand() );
          if ( name.exists() ) {
             output.setText(
                name.getName() + " exists\n" +
                ( name.isFile() ? "is a file\n" :
                                  "is not a file\n" ) +
                ( name.isDirectory() ? "is a directory\n" :
                                       "is not a directory\n" ) +
                ( name.isAbsolute() ? "is absolute path\n" :
                                      "is not absolute path\n" ) +
                "Last modified: " + name.lastModified() +
                "\nLength: " + name.length() +
                "\nPath: " + name.getPath() +
                "\nAbsolute path: " + name.getAbsolutePath() +
                "\nParent: " + name.getParent() );
          if ( name.isFile() ) {
                try {
                   RandomAccessFile r =
                      new RandomAccessFile( name, "r" );
                   StringBuffer buf = new StringBuffer();
                   String text;
                   output.append( "\n\n" );
                   while( ( text = r.readLine() ) != null )
                      buf.append( text + "\n" );
                   output.append( buf.toString() );
                catch( IOException e2 ) {
                   JOptionPane.showMessageDialog( this,
                      "FILE ERROR",
                      "FILE ERROR", JOptionPane.ERROR_MESSAGE );
             else if ( name.isDirectory() ) {
                String directory[] = name.list();
                output.append( "\n\nDirectory contents:\n");
                for ( int i = 0; i < directory.length; i++ )
                   output.append( directory[ i ] + "\n" );
          else {
             JOptionPane.showMessageDialog( this,
                e.getActionCommand() + " Does Not Exist",
                "FILE ERROR", JOptionPane.ERROR_MESSAGE );
       public static void main( String args[] )
          FileTest app = new FileTest();
          app.addWindowListener(
             new WindowAdapter() {
                public void windowClosing( WindowEvent e )
                   System.exit( 0 );
    }

  • Are inputstream and outputstream independent of eachother ?

    <b><u>Code snippet 1) </u></b><br>
    ByteArrayInputStream inputPDFStream = (ByteArrayInputStream) <SOME INPUT STREAM OBJECT>;<br>
    byte [] bArray = new byte [inputPDFStream.available()];<br>
    //Reading into byte array.<br>
    inputPDFStream.read( bArray );<br>
    //Dumping byte array contents onto file system.<br>
    File file = new File("//exchange//EPP//template//test_PDF_OnPortal.pdf");<br>
    FileOutputStream os = new FileOutputStream(file);<br>
    os.write(bArray);<br>
    os.flush();<br>
    os.close();<br>
    //Closing input stream, after all operations have been performed.<br>
    <b>inputPDFStream.close();</b><br>
    <br>
    <b><u>Code snippet 2)</u></b><br>
    ByteArrayInputStream inputPDFStream = (ByteArrayInputStream)pdfObject.createPDF();<br>
    byte [] bArray = new byte [inputPDFStream.available()];<br>
    int iBytesRead = inputPDFStream.read( bArray );<br>
    /*************** change starts here ************/<br>
    //Closing input stream immediately after it has been read from.<br>
    <b>inputPDFStream.close();</b><br>
    /*************** change ends here ************/<br>
    File file = new File("//exchange//EPP//template//test_PDF_OnPortal.pdf");<br>
    FileOutputStream os = new FileOutputStream(file);<br>
    os.write(bArray);<br>
    os.flush();<br>
    os.close();<br>
    /*************** change starts here ************/<br>
    // commented this line of code and shifted it above.<br>
    <b>//inputPDFStream.close(); </b><br>
    /*************** change ends here ************/<br>
    <br><br>               
    <b><u>Questions -</u></b> <br>
    <br>
    1) Are inputstream and outputstream objects totally independent of eachother ?<br>
    2) Will the change in the position of the "inputstream.close()" method as shown above, affect the writing of the file to the file system ?
    In other words, will the outcome of an "FileOutputStream.write(), flush() or close()" depend on when the inputstream object is closed as seen in code snippet (2) ?<br>
    3) Assuming that the output buffer is flushed, will any data that you try to write using the OutputStream.write() method, be written to the outputstream target (whether a file, or response object), irrespective of whether the inputstream is active at that point of time ??<br>
    <br>
    Thanks,<br>
    Navneet.<br>
    Changes made by -

    Hey kaj...Do you have any idea about the "not normal"
    situations in which case the input and output streams
    might influence eachother ? ;)Those cases are when both streams comes from a resource which closes both streams when one of them is closed. It's very rare to see, but I've seen some socket implementations which does that.
    Kaj

  • How to print the content of LinkedList int[] and LinkedList LinkedList ?

    Hi guys, its been a long time since i posted here, and now im coming back to programming using java. My problem is, how can i print the content of the list?
    Example:
    LinkedList<int[]> list = new LinkedList<int[]>;
    int[] input = {1,2,3,4,5};
    int[] input2 = {2,32,43,54,65};
    list.add(input);
    list.add(input2);
    how can i print all the content of the linkedlist?
    Please help me..I know its a dumb question but i really dunno how.
    here is the code:
    import java.util.LinkedList;
    import java.util.Scanner;
    import java.util.Arrays;
    public class Test{
         static void printThis(String[] in){
              System.out.print("Value: ");
              for(int i = 0;i<in.length;i++){
                   System.out.print(in[i] + " ");
              System.out.println();
         static void reset(String[] val){
              for(int i = 0;i<val.length;i++){
                   val[i] = "";
         public static void main(String[] args){
              LinkedList<String[]> list = new LinkedList<String[]>();
              LinkedList<String> listTrans = new LinkedList<String>();
              System.out.print("Enter the number of records: ");
              Scanner s = new Scanner(System.in);
              int numOfRecords = s.nextInt();
              System.out.print("Enter the number of records per run: ");
              s = new Scanner(System.in);
              System.out.println();
              int numOfRecordsInMemory = s.nextInt();
              String[] getData = new String[numOfRecords];
              String[] transferData = new String[numOfRecordsInMemory];
              int numOfRuns = 0;
              int counter = 0;
              for(int i = 0;i<numOfRecords;i++){
                   counter++;
                   System.out.print("Enter value number " + counter + ": ");
                   Scanner scan = new Scanner(System.in);
                   getData[i] = scan.next();
                   listTrans.add(getData);
              if(getData.length%numOfRecordsInMemory == 0){
                   numOfRuns = getData.length/numOfRecordsInMemory;
              }else if(getData.length%numOfRecordsInMemory != 0){
                   numOfRuns =(int)(getData.length/numOfRecordsInMemory)+ 1;
              System.out.println();
              System.out.println("Number of Runs: " + numOfRuns);
         int pass = 0;
         System.out.println("Size of the main list: " + listTrans.size());
         while(listTrans.size() != 0){
              if(listTrans.size() >= numOfRecordsInMemory){
                   for(int i = 0;i<numOfRecordsInMemory;i++){
                        transferData[i] = listTrans.remove();
                   System.out.println("Size of the list: " + listTrans.size());
                   printThis(transferData);
                   System.out.println();
                   Arrays.sort(transferData);
                   list.add(transferData);
                   reset(transferData);
              }else if(listTrans.size() < numOfRecordsInMemory){
                   pass = listTrans.size();
                   for(int k = 0;k<pass;k++){
                        transferData[k] = listTrans.remove();
                   System.out.println("Size of the list: " + listTrans.size());
                   printThis(transferData);
                   System.out.println();
                   Arrays.sort(transferData);
                   list.add(transferData);
                   reset(transferData);
    //This is the part that is confusing me.
    //im trying to print it but its not working.
              System.out.println("Size of the next list: " + list.size());
    //          for(int i = 0;i<list.size();i++){
    //                    System.out.println();
    //               for(int j = 0;j<list.get(i)[j].length();j++){                    
    //                    System.out.print(list.get(i)[j] + " ");

    Here's the funnest, mabye clearest way you could do it: Use 2 Mappers
    package tjacobs.util;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    import tjacobs.Arrays;
    public class Mapper <T>{
         public static interface MappedFunc<T> {
              void map(T value);
         public Mapper(T[] vals, MappedFunc<T> function) {
              this (new Arrays.ArrayIterator<T>(vals), function);
         public Mapper(Iterator<T> iterator, MappedFunc<T> function) {
              while (iterator.hasNext()) {
                   function.map(iterator.next());
         public static void main(String[] args) {
              String[] s = new String[] {"a","b", "c", "abc", "ab"};
              MappedFunc<String> func = new MappedFunc<String>() {
                   public void map(String s) {
                        if (s.toLowerCase().startsWith("a")) {
                             System.out.println(s);
              Mapper m = new Mapper(s, func);
    }

  • Converting string into inputstream and outputstream Jsch (ssh connection)

    hi,
    I'm not really sure if this is the place where i should ask this, but if it is so then tell me!
    So my problem is that everything works just fine with input output streams like in this code, but i need to change this input stream into string messadge(Which would work!!)
    The main problem is not that i can't change string to inputstream, but that when i use inputstream every commands works, and when i try to do the same with sting>inputstream this doesn't work...
    unfortunatelly newgrp server; or newgrp doesn't rerally work just frezzes :/
    anyway i solved the initial problem, because Jsch have two (probably more methods of sending info to unix server, but because there is no documentation htere no way to know :D)
    methods of sending info to server : exec and shell , the exec sends one command and only works with commands like date;ls... now the shell can easily send any type of command including newgrp server1, and everything works :)
    so we connect to the server(passw,user,host) then excecute commands, this code works perfectle but the commented code// doesn't work :
    JSch jsch=new JSch();
    String host=null;
    String user="me1234";
    host="super.server.co.uk";
    String passw="12345";
    Session session=jsch.getSession(user, host, 22);
    session.setPassword(passw);
    session.setConfig("StrictHostKeyChecking", "no");
    session.connect();
    Channel channel=session.openChannel("shell"); //the power of shell, if i use exec doesn't excecute newgrp...
    //String command = "newgrp xxxx;"; //this doesn't work ...
    //InputStream is = new ByteArrayInputStream(command.getBytes("UTF-8"));
    //channel.setInputStream(is);
    //then somehow printout the response from server...
    channel.setInputStream(System.in); // well instead of this I'd prefer channel.send(command);
    channel.setOutputStream(System.out);
    channel.connect();
    Edited by: 842778 on 14-Mar-2011 01:42

    You seem to be leaving out the newlines.

  • Design choice between ArrayList and LinkedList

    Can someone clarify me which is better suited (efficient) for use?
    It appears to me that both can be used very much interchangeably at least from functionality point of view. :(

    Using the following code (and I'm sure someone will come nitpicking about it) I get the (expected, at least by me from prior experience) result that iteration over a LinkedList is about twice as fast as iteration over an ArrayList, but lookup operations on an ArrayList are substantially faster:
    package jtw.test;
    import java.util.*;
    public class SpeedTest {
        public static void main(String... args) throws Exception {
            List<Integer> linked = new LinkedList<Integer>();
            List<Integer> arr = new ArrayList<Integer>();
            for (int i = 0; i < 1e3; i++) {
                linked.add(i);
                arr.add(i);
            long r = 0;
            Date startLinked = new Date();
            for (int i = 0; i < 1e3; i++) {
                for (Integer q: linked) {
                     r += q;
            Date stopLinked = new Date();
            System.out.println("Total: " + r);
            r = 0;
            Date startArr = new Date();
            for (int i = 0; i < 1e3; i++) {
                for (Integer q: arr) {
                     r += q;
            Date stopArr = new Date();
            System.out.println("Total: " + r);
            System.out.println("LinkedList iteration: " + startLinked + " to " + stopLinked + " took " + (stopLinked.getTime() - startLinked.getTime()));
            System.out.println(" ArrayList iteration: " + startArr + " to " + stopArr + " took " + (stopArr.getTime() - startArr.getTime()));
             r = 0;
            startLinked = new Date();
            for (int i = 0; i < 1e3; i++) {
                for (int j = 999; j >= 0; j--) {
                     r += linked.get(j);
            stopLinked = new Date();
            System.out.println("Total: " + r);
            r = 0;
            startArr = new Date();
            for (int i = 0; i < 1e3; i++) {
                for (int j = 999; j >= 0; j--) {
                     r += arr.get(j);
            stopArr = new Date();
            System.out.println("Total: " + r);
            System.out.println("LinkedList lookup: " + startLinked + " to " + stopLinked + " took " + (stopLinked.getTime() - startLinked.getTime()));
            System.out.println(" ArrayList lookup: " + startArr + " to " + stopArr + " took " + (stopArr.getTime() - startArr.getTime()));
    }Gets the result:
    D:\jdk1.6.0_05\bin\java -Didea.launcher.port=7540 "-Didea.launcher.bin.path=C:\Program Files\JetBrains\IntelliJ IDEA 8.0.1\bin" -Dfile.encoding=windows-1252 -classpath "D:\jdk1.6.0_05\jre\lib\charsets.jar;D:\jdk1.6.0_05\jre\lib\deploy.jar;D:\jdk1.6.0_05\jre\lib\javaws.jar;D:\jdk1.6.0_05\jre\lib\jce.jar;D:\jdk1.6.0_05\jre\lib\jsse.jar;D:\jdk1.6.0_05\jre\lib\management-agent.jar;D:\jdk1.6.0_05\jre\lib\plugin.jar;D:\jdk1.6.0_05\jre\lib\resources.jar;D:\jdk1.6.0_05\jre\lib\rt.jar;D:\jdk1.6.0_05\jre\lib\ext\dnsns.jar;D:\jdk1.6.0_05\jre\lib\ext\localedata.jar;D:\jdk1.6.0_05\jre\lib\ext\sunjce_provider.jar;D:\jdk1.6.0_05\jre\lib\ext\sunmscapi.jar;D:\jdk1.6.0_05\jre\lib\ext\sunpkcs11.jar;F:\dev\Euler\out\production\Euler;C:\Program Files\JetBrains\IntelliJ IDEA 8.0.1\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain jtw.test.SpeedTest
    Total: 499500000
    Total: 499500000
    LinkedList iteration: Wed Jan 21 07:32:41 CET 2009 to Wed Jan 21 07:32:41 CET 2009 took 30
    ArrayList iteration: Wed Jan 21 07:32:41 CET 2009 to Wed Jan 21 07:32:41 CET 2009 took 53
    Total: 499500000
    Total: 499500000
    LinkedList lookup: Wed Jan 21 07:32:41 CET 2009 to Wed Jan 21 07:32:42 CET 2009 took 424
    ArrayList lookup: Wed Jan 21 07:32:42 CET 2009 to Wed Jan 21 07:32:42 CET 2009 took 22
    Process finished with exit code 0Given the internal representation of the datatypes, this is to be expected.

  • InputStream and BLOB

    Hello
    I run java 1.4/Postgresql 7.1.3
    I would to get a binary image (BLOB) from a database
    and write it ot a file
    So i use Blob => getBinaryStream => file
    The length of the blob is OK :5836010 but the size
    of the file is only 4845 bytes !!!
    Here my code :
    try{
         conn.setAutoCommit(false);
         st = conn.createStatement();
         rs = st.executeQuery("SELECT * FROM image WHERE nom='image1.tif'");
         if (rs != null) {
         rs.first();
         String str = new String (rs.getString("nom"));//le contenu du champ nom     
         System.out.println(str);
         img = rs.getBlob("image");//recup du blob
         long len = img.length();
         System.out.println(len);// length is OK :5836010
         in = img.getBinaryStream();
         FileOutputStream fileOutStream = new FileOutputStream("/tmp/tot.tif");
         byte[] buffer = new byte[10]; //buffer size
         int nbytes = 0; //
         while( (nbytes = in.read(buffer)) != -1 )
              fileOutStream.write(buffer, 0, nbytes); //write
         // Flush and close
         fileOutStream.flush();
         fileOutStream.close();
         in.close();
    Thanks
    cc

    I am experiencing a similar problem and would appreciate any help from anyone who has a clue (cause i've run out of resources).
    I can write blobs to Oracle. I can retrieve the blob, get the length with blob.length(); and i can verify that the blob is correct by using the blob.position(byte[], long) method to locate the beginning of a byte string anywhere in the blob but when I use either the blob.getBinaryStream() method or the blob.getBytes() method i get a null pointer. What up?
    Both of these code fragments should work for me, but neither do:
    java.io.InputStream in = blob.getBinaryStream();
    byte b;
    while ((in.read()) > -1) {
         b = in.read();
         System.out.println(b);
    long len = blob.length();
    byte [] data = blob.getBytes(1, len);
    for (int i = 0; i < len; i++) {
         byte b = data;
         System.out.println(b);
    I'm ready to commit hari kari.
    Help!
    -Jim Marks

  • Question about variable copying, referencing and LinkedList constructors.

    Is there any advantage in this recommendation?
    "In general, do make sure that you copy mutable arguments and mutable return values when appropriate."
    Now, according to this suggestion:
    public ClassName(LinkedList<String> list)
         this.list = new LinkedList<String>(list);
    Instead of public className(LinkedList<String> list)
         this.list = list;
    }I am confused about the situation where using the copy constructor would be appropriate as opposed to the second method.
    Can someone please explain which would be an ideal situation to use a copy constructor and when to use mere assignment?

    fantastic_ray wrote:
    Is there any advantage in this recommendation?
    "In general, do make sure that you copy mutable arguments and mutable return values when appropriate."If you don't copy mutable arguments and return values, then when you change the state ("contents") of the object, it will be seen by both the original reference and the copy. Sometimes you may want this. Sometimes you may know that no change will occur. You have to judge what's appropriate for your use. In general, though, if there's a chance the elments' states may change, you'll want to copy them.
    >
    Now, according to this suggestion:
    public ClassName(LinkedList<String> list)
         this.list = new LinkedList<String>(list);
    Instead of public className(LinkedList<String> list)
         this.list = list;
    It depends. After you do new ClassName(list), if the code that created the ClassName object is going to keep using the list and you don't want any changes it makes to be seen by the new object and vice versa, then yes, you'd want to do the former.

  • Difference between ArrayList class and LinkedList class

    I would like to ask what is the difference between the ArrayList class and the LinkedList class? If I use ArrayList class can I have a fixed size?
    Thank you for your answers.

    I often use LinkedList when I need a FIFO. When all you're doing is adding to the end of a list and removing the first element, it is definitely faster. Here's a quick SSCCE I wrote up to demonstrate:import java.util.*;
    public class ListTest {
       public static void main(String[] args) {
          LinkedList<Integer> linked = new LinkedList<Integer>();
          ArrayList<Integer> array = new ArrayList<Integer>();
          Integer[] values = new Integer[2500000];
          for (int i = 0; i < values.length; i++) {
             values[i] = new Integer(i);
          Random rand = new Random();
          boolean[] randDir = new boolean[values.length];
          for (int i = 0; i < randDir.length; i++) {
             randDir[i] = rand.nextBoolean();
          long startTime, endTime;
          startTime = System.currentTimeMillis();
          for (int i = 0; i < values.length; i++) {
             if (linked.size() > 0 && randDir) {
    linked.removeFirst();
    else {
    linked.addLast(values[i]);
    endTime = System.currentTimeMillis();
    linked.clear();
    System.out.println("linked:"+(endTime-startTime));
    startTime = System.currentTimeMillis();
    for (int i = 0; i < values.length; i++) {
    if (array.size() > 0 && randDir[i]) {
    array.remove(0);
    else {
    array.add(values[i]);
    endTime = System.currentTimeMillis();
    System.out.println("array:"+(endTime-startTime));
    array.clear();

  • InputStream and XML

    Hello,
    I've written a servlet which takes some XML from the request's input stream, parses it and then does some database-related stuff with the results.
    My problem is that additional header information is included in the input stream, thus making my XML parser fall over.
    I do a request.getInputStream() to get the input stream, which I then pass to my SAX handler's parse() method (which takes an InputStream object as one of its arguments).
    Upon testing, I notice that there is additional information at the start of the InputStream. It looks like this:
    POST /path/servletname HTTP/1.1
    host: <ip address>
    user-agent: Mozilla/5.0
    ... and so on
    It's only after this header information has completed that I can see the request XML. As such, when I pass the InputStream object to the parser, it's falling over as it is expecting "clean" XML from the start of the Input Stream.
    Is there any way I can remove the excess information at the start of the InputStream?
    Thanks for any information.

    Further question arising from what I've subsequently discovered:
    I've found that the problem is nothing to do with the "Poster" application I'm using to test my code, as described above. When my application first receives the request, it reads the InputStream using a BufferedReader, as part of the request is used for the response back.
    It's only after I do this that I subsequently try and re-read the InputStream to get the XML out and parse it. What I think is happened is that after I've read the InputStream the first time, I can't read it again.
    The parse() method of my XML parser takes either an InputStream or InputSource. I'm not familiar with either objects, but envisage creating a new InputStream or InputSource the first time I read the request InputStream which I can then pass to my parser. Can anyone give me some hints as to how to create InputStream or InputSource objects, please?
    Many thanks for any assistance.

  • When to choose ArrayList and LinkedList ?

    Please let me know which list type to use and when ? Pros Cons .. Advantages Disadvantages
    ArrayList vs LinkedList ?

    Here is a good place to start [http://www.google.co.uk/search?q=arraylist+vs+linkedlist] 154,000 hits. I think most of the arguments are covered here. ;]

  • InputStream and Reader

    For the program that I'm writing, I'm redirecting the default streams, so I made extended InputStream, overrode ALL the functions, and used System.setIn.
    However, a common class that I use for IO in my previous console programs use Readers. I figured out that I needed to return a
    (char) -1
    after my buffer has ended as the end-of-stream.
    However, if I only return it for a set number of times, like 1 or 50000 times, the Reader won't accept that end-of-stream, and keeps reading! If I don't stop returning the end-of-stream, the stream can't be read for a second time (the Reader keeps returning end-of-streams)! How should I solve this?

    You guys aren't understanding the purpose of the
    class. I want to redirect System.in.to a applet or a
    swing app. So, I want the Reader to accept the
    input, but not close the stream permenently. I hope
    that clear things up for a bit.Well, I had the same problem with my application, it would write the data fine, but not close the FileOutputStream, which caused my application to crash (because I put in safeguards) What I did was create variables for each thing being written, wrote a class, like:
    public void Create() //coded 4/12/2006
              create = new FileDialog(dialog,"New Game v1.0", FileDialog.SAVE);
              create.show();
              file_name = create.getFile();
              f = new File(file_name);
              if (file_name != null)
              { try
                        FileOutputStream fos = new FileOutputStream(file_name);
                        DataOutputStream dos = new DataOutputStream(fos);
                        level = "1";
                        cur_HP = "10";
                        max_HP = "10";
                        atk_str = "10";
                        def_str = "10";
                        cur_exp = "0";
                        exp_ned = "100";
                        loc_x = "0";
                        loc_y = "0";
                        dos.writeUTF(level);
                        dos.writeUTF(cur_HP);
                        dos.writeUTF(max_HP);
                        dos.writeUTF(atk_str);
                        dos.writeUTF(def_str);
                        dos.writeUTF(cur_exp);
                        dos.writeUTF(exp_ned);
                        dos.writeUTF(loc_x);
                        dos.writeUTF(loc_y);
                        System.out.println("File Created Sucessfully: " + file_name);
                        fos.close();
                   catch (IOException e)
                        System.out.println("There was an Error Creating the File: " + file_name);
                        System.out.println(e);
         }which opened the FileOutputStream and DataOutputStream, wrote the variables to the file (which were ints converted to a String), and closed the file. What I would try to do is to write your variables to the file, then put a end variable (like an int set to the value of 1728274672 or some other number of your choice), and when your reading your file, have an if/else statement like:
    if(temp_process[i] != 1728274672)
    process[i] = temp_process;
    i = i + 1;
    else
    bufferedvariable.close();
    i hope this makes sense
    Message was edited by:
    g@m3r

  • Differece between ArrayList and LinkedList

    Differece between ArrayList and LinkedList

    An array list is implemented as an array. A LinkedList is implemented as a series of separate nodes linked by references.
    Although they both support the same methods, that has performance implications. Linked lists are better at inserting and deleting arbitary elements, but are slow to reference an element by index.

  • How to parse the TelnetClient inputStream and remove the escape sequences ?

    Hi all,
    After inoking a telnet command (using the
    'org.apache.commons.net.telnet' library) the returned output is wrapped
    with escape sequence. For example, when sending "echo hello world" I
    get this result:
    echo
    *[4;46Hhello*
    *[4;52Hworld*
    *[5;1Hhello world*
    *[7;1HC:\Documents and Settings\Administrator>*
    It looks like a chars and line counter, so I was wondering whether
    there is an easier way to get it parsed in a more readable method.
    Thanks,
    Uri

    sabre150 wrote:
    Scheiner wrote:
    sabre150 wrote:
    Scheiner wrote:
    >
    Probably VT100 (of family) escape characters. Are you sure there is not a means of turning this off since it is not part of the TELNET specification.I used VT100 when I created the TerminalTypeOptionHandler. Can you suggest another Terminal type that will append this sequence?I'm not familiar with the package. I'm sure the Javadoc will suggest what other 'TerminalTypeOptionHandler' types are available.Hi, I changed the handler to use VT220 and it worked great!
    Thanks a lot for the help
    UriSorry but this is just silly! You don't want VT anything. As EJP says you want a 'dumb' terminal.Yes, got that after the tried the VT220. I will explore the JTA package and alter my code

Maybe you are looking for

  • ASR & multiple accounts --- Can I do this?

    I've been trying to clone my MacMini that has several user accounts set up. I can use ASR successfully, but the clone doesn't have the accounts in the login menu. The acct folders are on the hard drive, but not on the login page. How can I use ASR to

  • Photoshop Elements 11 Selection and brush tool not working right

    I have this problem where I select parts of an image I am trying to draw, and I want to fill the selected regions of the image with color but whenever I use the brush or the paint bucket tool to fill it, little tiny regions outside of the selection a

  • New g/l accounting

    HI Experts, What is parallel ledger accounts in new g/l accounting?

  • Firefox 3.6.8 no updates why no 5.0.1

    hard drive crash went back to older drive i left OS 10.5.8 and software still on did all the updates since its been a year Firefox problem: i used to use version 5.0.1 present version 3.x.x click on firefox help drop down to update well updated me to

  • Reboots every minute

    any help? Interval Since Last Panic Report:  1374886 sec Panics Since Last Report:          3 Anonymous UUID:                    7F9F4418-B50A-44AD-A7D9-3EF3FFAF8E12 Sat Mar 30 09:27:23 2013 panic(cpu 4 caller 0xffffff80002447d9): "zalloc: \"ipc kmsg