Input Stream and String

I need to create a string and then pass it as an inputStream to another program. I've looked at the API, I see the StringReader object. But I don't know how to convert it to an inputStream. I'd like to do the fastest thing available, because this is basically just for debugging purposes. Can anyone help?
Thanks

then pass it as an inputStream to another program.How do you want to pass it? via a socket? via a file?
else?I'd pass it through its' parameter
basically
parse(inp);
where inp is an inputStream. But instead of inp coming from a file. I need it to come from a string.

Similar Messages

  • Separate thread for input stream and output stream.

    Hi Techies,
    In a socket connection, can we run the input stream and output stream in separate threads. actually in my case, the input stream will be getting the input regularly and output stream will send data very rare. so if i impelment them in one class then unless there is data to send output stream will be blocked. i was thinking to impelment both the streams in separate threads. is it a good way? so how to implement it. your guidance will be of great help.
    thanks in advance.

    JavaBreather wrote:
    Hi Techies,
    In a socket connection, can we run the input stream and output stream in separate threads.I would say this is the most common way of handling sockets and threads. esp pre-NIO.
    Iis it a good way? so how to implement it. your guidance will be of great help.Once you have a socket, create two threads, one which does the reading and one which does the writing.
    You could use BlockingQueues to abstract access to these threads. i.e. the reading thread reads something from the socket and adds it to the BlockingQueue. The writing thread take()s something froma second BlockingQueue and writes it to the Socket. This way you add things to write or get thing to process by looking at the BlockingQueues.

  • Create HelpSet using input stream and not URL

    Hi All,
    I looked over the docs and apis and I was not able to find any way to create a HelpSet from an input stream.
    Basically all I have is are input streams to the help files and not URLs, is there a way to initialize the help set with that?
    thanks

    Never compare Strings using Object equality or inequality ("==" resp. "!=").
    Use [url http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#equals(java.lang.Object)]String#equals (or [url http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#indexOf(java.lang.String)]String#indexOf or [url http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#matches(java.lang.String)]String#matches).
    Please use code tags when posting code. This means wrapping your text between [code[/b]][[/b]code] tags. See the [url http://forum.java.sun.com/help.jspa?sec=formatting]Formatting tips.

  • BizTalk Stored Proce-passing XML as one of the Input parameter and String as another parameter

    I have a requirement in BizTalk that
    - I will receive XML from Source and i need to submit this XML data and two other string parameters in  SQL storeprocedure  as a parameters and submit data
    Ex: My_SP(myID Integer INPUT,myXML xml Input,mystring OUT)
    Could you please help me how call storeprocedure and submit multiple parameters in BizTalk.

    you can execute stored procedure by generating schemas from WCF-SQL Adapter.
    for passing parameters you will have to do the mapping to the Generated schema for Stored proc.
    I would suggest to do this in Message Assignment shape, there you can easily assign all the parameters.
    Integer and String parameters can be assigned from normal variables and XML parameter can be inserted as suggested by Abhishek-
    xmldoc=requestMsg;
    varOuterstring=xmldoc.Outerxml.Tostring();
    Please refer the below article.
    https://www.packtpub.com/books/content/new-soa-capabilities-biztalk-server-2009-wcf-sql-server-adapter
    http://msdn.microsoft.com/en-us/library/dd787968.aspx
    Thanks,
    Prashant
    Please mark this post accordingly if it answers your query or is helpful.

  • When using URLConnection read input stream error

    hi,
    In my applet I build a URLConnection, it connect a jsp file. In my jsp file I refer to a javaBean. I send two objects of request and response in jsp to javaBean. In javabean return output stream to URLConnect. At that time a error happened.WHY???(Applet-JSP-JAVABean)
    Thanks.
    My main code:
    APPLET:(TestApplet)
    URL url = new URL("http://210.0.8.120/jsp/test.jsp";
    URLConnection con;
    con = url .openConnection();
    con = servlet.openConnection();
    con.setDoInput( true );
    con.setDoOutput( true );
    con.setUseCaches( false );
    con.setRequestProperty( "Content-Type","text/plain" );
    con.setAllowUserInteraction(false);
    ObjectOutputStream out;
    out = new ObjectOutputStream(con.getOutputStream());
    Serializable[] data ={"test"};
    out.writeObject( data );
    out.flush();
    out.close();
    //until here are all rigth
    ObjectInputStream in = new ObjectInputStream( con.getInputStream() );//happened error
    JSP:
    TestBean testBean = new TestBean ();
    testBean .execute(request, response);
    JAVABEAN:
    public void execute( HttpServletRequest request,
    HttpServletResponse response )
    ObjectInputStream in = new ObjectInputStream( request.getInputStream() );
    String direct = (String) in.readObject();
    System.out.prinltn("direct");
    ObjectOutputStream out = new ObjectOutputStream( response.getOutputStream() );
    SerializableSerializable[] data ={"answer"};
    out.writeObject( data );
    out.flush();
    out.close();
    Error detail:
    java.io.StreamCorruptedException: invalid stream header
         at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:729)
         at java.io.ObjectInputStream.<init>(ObjectInputStream.java:251)
         at TestApplet.postObjects(TestApplet.java:172)

    you have to pay attention to the sequence of opening the streams.
    The following example is: client sends a string to server, and servlet sends a response string back.
    client side:
             URL url = new URL( "http://152.8.113.149:8080/conn/servlet/test" );
             URLConnection conn = url.openConnection();   
             System.out.println( "conn: " + conn );
             conn.setDoOutput( true );
             conn.setDoInput( true );
             conn.setUseCaches( false );
             conn.setDefaultUseCaches (false);
             // send out a string
             OutputStream out = conn.getOutputStream();
             ObjectOutputStream oOut = new ObjectOutputStream( out );
             oOut.writeObject( strSrc ); 
             // receive a string
             InputStream in = conn.getInputStream();     
             ObjectInputStream oIn = new ObjectInputStream( in );
             String strDes = (String)oIn.readObject();server side
             // open output stream
             OutputStream out = res.getOutputStream();  
             ObjectOutputStream oOut = new ObjectOutputStream( out );
             // open input stream and read from client
             InputStream in  = req.getInputStream();
             ObjectInputStream oIn = new ObjectInputStream( in );
             String s = (String)oIn.readObject();
             System.out.println( s );
             // write to client
             oOut.writeObject( s + " back" ); I have the complete example at http://152.8.113.149/samples/app_servlet.html
    don't forget to give me the duke dollars.

  • Java.lang.Process input stream waiting until process is complete to print

    I have tried to simplify this problem as much as possible. Basically, I have a java.lang.Process which executes a simple C program.
    test.c
    #include <stdio.h>
    #include <unistd.h>
    int main()
      printf("foo\n");
      sleep(2);
      printf("bar\n");
    ...The process has an input stream and error stream handler each on a separate thread. I have tried both buffered and unbuffered (BufferedReader, BufferedInputStream, InputStreamReader...) stream handlers. Both produce the same problem of waiting until the process has exited to receive anything from the process's streams.
    The only time this does not happen is when I call fflush(stdout); after each printf(). This can't be a solution because the real application calls a massive C application which would require thousands of fflush()'s to be added. What is causing this to happen? This doesn't happen when the C program is executed from the shell. Is there a way the InputStream can be forced to extract from the stream?

    hi.....
    I have closed the output stream of the process as you told me to do...
    The hitch is that, if my program contains only printf() statements,it works fine
    as soon as scanf() statement is encountered within the C code,it is totally neglected,and the output comes as if no scanf() statement existed in the C code.
    Consequently the thread doesnt wait for input which was bound for scanf() from the thread
    the code...
        public void run()
         try
             PrintWriter out = new PrintWriter(socket.getOutputStream(),true);
             BufferedReader in = new BufferedReader(
                            new InputStreamReader(
                            socket.getInputStream()));
             try
                     Process p;
              p=new ProcessBuilder("./a.out").start();
                     PrintWriter exOut=null;
                     BufferedReader exIn=null;
              exOut = new PrintWriter(p.getOutputStream(),true);
              exIn = new BufferedReader(
                           new InputStreamReader(
                           p.getInputStream()));
                  //String inputLine="", outputLine="";        
                  String str="";
                     int c;          
                  while(true)                   
                        //System.out.println("In While");
                  str="";exOut.close();                  
                        while((c=exIn.read())!=-1)
                                 str=str+(char)(c);
                                    System.out.print(str);
                        str=str+(char)(0);
                        System.out.print(str+"outside");
                        out.print(str);
                        sleep(100);
                        try
                            int x=p.exitValue();
                              out.print(str);
                   System.out.print("Bye 1");
                            String str1="Bye"+(char)(0);
                   out.println(str1);              
                   break;
                        catch(IllegalThreadStateException e)
                            //System.out.println("The Process has not ended yet");
                        //str=str+((char)-1);
                        //System.out.print(str+"Control reaches here too");
                        str="";
                        exOut = new PrintWriter(p.getOutputStream(),true);//I have tried to run the program without this also but the effect is the same
                        while((c=in.read())!=-1)
                            str=str+(char)(c);                                    
                        if(str.contentEquals(""))
                                System.out.print("Bye 2");
                                String str1="Bye"+(char)(0);
                                out.println(str1); 
                                p.destroy();
                                exOut.close();
                                exIn.close();
                                out.close();
                                in.close();        
                                socket.close();
                                break;
                        //str=str+(char)(0);
                  exOut.print(str);
                        try
                            int x=p.exitValue();
                            System.out.print("Bye 3");
                            String str1="Bye"+(char)(0);
                   out.println(str1);
                            break;
                        catch(IllegalThreadStateException e)
                            //System.out.println("The Process has not ended yet");
                  /*while ((inputLine = in.readLine()) != null)
                        exOut.println(inputLine);
                        outputLine=exIn.readLine();
                        //outputLine=inputLine;
                        //out.println(outputLine);}*/                   
             exOut.close();
             exIn.close();
             catch(IOException e)
                  System.err.println("Accept failed."+e);
             out.close();
             in.close();        
             socket.close();
         catch (Exception e)
             e.printStackTrace();
    }

  • Buffered Input stream - data corruption

    Hi
    I'm using the following code to transfer data to a file
    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(
            new StringBuffer(path).append(part.getFileName()).toString()));
        BufferedInputStream in = new BufferedInputStream(part.getInputStream());
        while (in.available() > 0) {
          out.write(in.read());
        out.close();
        in.close();It write the image and text files properly
    But all the application based data like zip files,.doc files are getting corrupted
    How do I solve it? What is the problem with the code?
    Help pls

    What a waste of buffers that code is.
    We don't know how you might be corrupting the data
    coming in because you haven't show us what that code
    is like. All we see is part.getInputStream which is
    hardly enough to make a diagnosis.OOps
    private void writeAttachment(BodyPart part, String path) throws
          MessagingException,
          FileNotFoundException, IOException {
           //Make new dir
        new File(path).mkdirs();      
        if (this.EnsileCall)
             this.log("Ensile writing <<" + part.getFileName() + ">> of size = " + part.getSize());     
        // Write to file
        BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(
                new StringBuffer(path).append(part.getFileName()).toString()));
            BufferedInputStream in = new BufferedInputStream(part.getInputStream());
            while (in.available() > 0) {
              out.write(in.read());
        out.close();
        in.close();
    part.getInputStream() Part corresponds to a message body part in a mail(The attachment)
    I'm getting the mail attachment's input stream and writing it to a file.

  • Help with input streams

    hello/
    i need an InputStream for the constructor of my SAXBuilder object below.
    i have this working, however, i would like to read everything from the
    InputStream first and save the value into a String object before I pass the InputStream to the SAXBuilder. how do i go about doing this?
    thx/f
    // Open an input stream to the URL and read it into a byte array.
    BufferedInputStream bufferedInput =
    new BufferedInputStream(connection.getInputStream());
    // Create a new SAX builder.SAXBuilder builder = new SAXBuilder();
    // Read the portal response back and save it as an XML document.
    Document response = builder.build(bufferedInput);

    But you have now read from your input stream and need to reset it so
    InputStream is = urlConn.getInputStream();
    if ( is.markSupported() ) {
       is.reset();
    else {
       is.close();
       is = new ByteArrayInputStream( docStr.toString().getBytes() );
    Now you can pass your InputStream into your SaxBuilder, and have your string of what it contains.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How  encode streaming and publish it to  youtube and livestream in one process ?

    Dears ,
    We  start encode  to  youtube  and another process to livestreeam.com  , that conusmes   much of cpu ,
    I want to configure to start encode to youtube and livestream.com in one process that will minimize CPU consuming for encoding  by 50%
    Kindly advice how to configure  it ?
    thanks.

    There isn't any good way around this.  If you want to send a stream to two different platforms... you have to have two different encoders.  In order for FMLE to take the output of a single compressed stream and deliver it to two different streaming servers (Livestream and YouTube) you have to be running a streaming server.
    A streaming server will take one single "input" stream, and deliver it to multiple endpoints.  Those endpoints could be viewers who want to watch, or they could be other streaming servers.  In any event, what your asking for is handled by a streaming server... and FMLE is an encoder, not a streaming server.
    What your asking to do can be done... but it's going to be very expensive, and I'm assuming you want to keep this low cost.  Your cheapest solution is to use a computer that has the CPU horsepower to run two copies of FMLE -- each encoding and sending a stream to the two different endpoints (Livestream and YouTube)... or simply purchase a second computer and have each computer handle each stream encoding individually.

  • Storing input stream in a buffer

    Hi, what is the best way to read an input stream and save it into a buffer?
    Thanks,
    Andrea

    Not sure if any of the following are an improvement or not. But here are just a few thoughts. Why handle all the byte array allocation yourself? IMO, it would be easier to simply use a ByteArrayOutputStream at that point. The listeners can call toByteArray() and be passed an offset and length of what was read.
    Now that I think about it, you could probably make it a bit more generic even than that. For example, here is a class I end up using all the time:
    public final class Pipe
        /** Buffer size to read in and output. */
        private static final int DEFAULT_BUFFER_SIZE = 2048;
         * Private constructor.  Use public static facade methods instead.
        private Pipe()
            super();
         * Pipes the specified binary data to the specified output stream.
         * @param   target                      Binary data to output
         * @param   out                         Stream to write
         * @throws  IOException
        public static final void pipe(final byte[] target, final OutputStream out)
            throws IOException
            assert (target != null) : "Missing byte array";
            assert (out != null) : "Missing output stream";
            pipe(new ByteArrayInputStream(target), out, true);
         * Reads from the specified input stream and returns all data as an in-memory.
         * binary array.  Note:  Since streams may be of any arbitrary size, this
         * method requires that you wrap your original stream in a {@link FiniteInputStream}.
         * Please ensure that this method is only used to read in data under, say, 2mB.
         * @param   in                          Stream to read
         * @return  byte[]                      Binary data read
         * @throws  IOException
        public static final byte[] pipe(final FiniteInputStream in)
            throws IOException
            ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
            pipe(in, byteOut, true);
            return byteOut.toByteArray();
         * Reads from the specified input stream and outputs immediately to the specified.
         * output stream.  <br>
         * <br>
         * If you have any confusion about which <code>Pipe</code> method to use, choose
         * this one.  It has the lowest memory overhead and is the most efficient.  Always
         * choose this method when streaming large amounts of data or content.
         * @param   in                          Input stream to read
         * @param   out                         Output stream to write
         * @param   close                       Close both stream if true
         * @return  long                        Byte count piped
         * @throws  IOException
        public static final long pipe(final InputStream in, final OutputStream out, final boolean close)
            throws IOException
            assert (in != null) : "Missing input stream";
            assert (out != null) : "Missing output stream";
            long bytesPiped = 0L;
            byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
            try
                int bytesRead = in.read(buffer);
                while (bytesRead >= 0)
                    if (bytesRead > 0)
                        out.write(buffer, 0, bytesRead);
                        bytesPiped = bytesPiped + bytesRead;
                    bytesRead = in.read(buffer);
                out.flush();
                return bytesPiped;
            finally
                if (close)
                    IoHelper.close(in);
                    IoHelper.close(out);
    }You simply could add the listener feature (which I do think is useful and elegant). Note the FiniteInputStream and FiniteOutputStream are just sub-classes of FilterInputStream and FilterOutputStream that allow you to limit how many bytes are piped, if desired.
    - Saish

  • Buffered Input stream that increases internal buffer dynamically

    I need to parse an input stream until I find a <META> tag with character encoding. I then need to reset to the beginning of the input stream and start parsing the stream again with the correct character encoding.
    BufferedInputStream provides mark() and reset() methods which can be used to accomplish this task. However, the input stream data can be 1MB size and the only way I can think of forcing the BufferedInputStream to hold that content size is by specifying the size during construction.
    I don't want to initialize the content size during construction of the BufferedStream for every data file I parse because some documents could have the tag in the beginning of the file and it could be waste of memory.
    Question: Is there already a class which allows to set the maximum buffer size and which grows gradually to that size rather than during construction.
    Thanks for any help.

    DrClap, I connect to a webserver and request a file. I just use the InputStream returned by the HttpResponse object to read the file. So, the answer to your question is I can't close and reopen the file.
    Jawahar

  • GZIP compressing input stream?

    I have an API which takes an InputStream for feeding in large binary data.
    Suppose I want to write a wrapper around that API which GZIPs the data on the fly. This would require some kind of InputStream which will compress the data with GZIP on the fly. However, GZIPInputStream can only decompress on the fly.
    Does anyone know of a way to do the exact opposite?

    So, don't store the entire file in memory. Storing a compressed version of the file isn't much of a
    solution.You're not paying attention. I said I can't FIT the data in memory. If I can't fit it in memory, why would I be trying to store it in memory? Hence why I want to store it in a DATABASE.
    If you can't grasp the most simple of uses for a database, there isn't a lot of hope for you in this field in the future.
    You actually can use a ByteArrayOutputStream, to generate the compressed bytes, as I described, > but you apparently we're paying attention, which at this point is all I expect from you.Okay, how? If I simply put all the uncompressed bytes into the GZIPOutputStream and that output stream is attached to the ByteArrayOutputStream, I will run out of memory.
    Code, please. In other words, prove that what you say is possible.
    You are allowed to. It's debatable whether it's a good idea. Anyway this is the first time you
    mentioned JDBC. Back when we wanted to help you (before you called us idiots) that might
    have been useful information. It's easier to help people when you have information about what
    the hell theyr'e trying to do.I did say that we have an API which takes an input stream, and that this was the reason why I had to pass in an input stream. It doesn't matter whether it's JDBC, or anything else. What is important is that it takes an input stream.
    Actually, it's pretty cheap. It's probably cheaper than the cost of the extra RAM you'll need doing
    extraneous compression/decompression.Actually, compression is generally fairly inexpensive, RAM-wise. You lose some CPU, but CPU is even cheaper than the amounts of disk space which we would otherwise need for this.
    We're storing gigabytes of data, and
    I would rather not have to actually store gigabytes
    of data.So, you're not actually storing it now?We're storing it compressed, which makes it take less space. You do know what compression is, right?
    A redesign might end up removing GZIP entirely. But maybe not. It's hard to say because you still
    haven't given a lot of details, and given your attitude I'm certain your estimation of the project is
    entirely wrong anyway. At this point I don't care either way. Good luck with your project to create
    an unmaintainable buggy monstrosity.Actually, this is trying to make the project more maintainable. Right now, we have multiple components each doing the gzipping in their own sections. I'm trying to make a component which can generically take a data stream, and store it into the database compressed.
    You're partially right, though. A redesign would remove GZIP entirely -- I would use Deflate as-is. Deflate has convenient methods for working with smaller chunks of data, and I could borrow much of the code from InflateInputStream and modify it to create DeflateInputStream. The next version of our app, once we're willing to break compatibility, will probably do this.

  • Convert result set into input stream

    Hi,
    I have result set with me having 93 columns with 1 lac rows. I want to download the result set as xls file.
    Because of the data set size is large, i'm not able to hold the data in java object. So i'm trying to convert result set to input stream and giving this input stream to servlet output stream by specifying the contentType as text/xls.
    I'm not able to convert result set into input stream.
    Could you provide a solution here...
    Thanks,
    Rajesh

    1 - JDBC is the wrong way to extract this data. It's like "What's the fastest way
    to copy the Oxford English Dictionary using tweets?" I would research the
    DBMS's bulk extract functionality.
    2 - Are you dead-set absolutely sure you need to do this at all? What can you
    do with the data all in one flat file that you cannot do with SQL access to the
    data?
    3 - If you want to convert all the columns into one (not that it's a huge
    win or anything), you can use the DBMS's conversion and concatenation
    functionality in your SQL. So instead of
    "select col1, col2, col3, .... from MyBigTable"
    do (change this to whatever conversion function syntax and concat syntax your DBMS needs)
    "select convert(col1, varchar) concat ' ' concat convert(col2, varchar) concat ' ' concat convert(col3, varchar) ... from MyBigTable"
    so the result set you get is a single column.
    Joe

  • Reset input stream

    Is there any way to mark/reset (or something comparable) an input stream that does not support the actual mark/reset methods? I'm using a DataInputStream, which contains a FileInputStream, and I've gotten an IOException saying mark/reset is not supported. Is there any other way to do it?

    I'm basically just reading bytes of binary data from a file, and I want to include a feature to reset and start reading again from the beginning. here's some of my code:
    public static void readWithDelay() {
            byte buf[] = new byte[100000];
            byte skipbytes[] = new byte[2];
            int length = 0, prevtime, time, lastprevtime=0, num=0, timecheck,skiplength=0;
            long period, filesize=0, bytecount = 0;
            double val = 0.0;
            try {
                begin = System.currentTimeMillis();
                // open the .pgem file stream
                try {
                    binfile = new DataInputStream(new FileInputStream(getFname()));
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(new JFrame(), "File not Found. Try Again.", "Open File error", JOptionPane.ERROR_MESSAGE);
                try {
                    File file = new File(getFname());
                    filesize = file.length();
                } catch (Exception e) {
                    e.printStackTrace();
                try {
                    // open the socket to socket on localhost
                    Socket socket = new Socket(getText(), port);  // 1222 is TagBrowsers port
                    socket.setTcpNoDelay(true); // Disable TCP Nagle algorithm
                    socketOutputStream = new DataOutputStream(socket.getOutputStream());
                } catch (UnknownHostException u) {
                    JOptionPane.showMessageDialog(new JFrame(), "Host Not Found. Defaulting to localhost", "Socket error", JOptionPane.ERROR_MESSAGE);
                    Socket socket = new Socket("localhost", 1222);  // 1222 is TagBrowsers port
                    socket.setTcpNoDelay(true); // Disable TCP Nagle algorithm
                    socketOutputStream = new DataOutputStream(socket.getOutputStream());
                bos = new BufferedOutputStream(socketOutputStream, 10000);
                // loop copying file to output buffer until endfile
                rate=rate/10;
                start();
                begin = System.currentTimeMillis();
                //binfile.mark(500000000); <<<<<Tried to mark it here>>>>
                for (int i=0;i<24;i++) {
                    buf[i] = binfile.readByte();
                    bytecount++;
                time = ((buf[6] & 0xff) << 24) | ((buf[7] & 0xff) << 16) | ((buf[8] & 0xff) << 8) | (buf[9] & 0xff);
                length = ((buf[14] & 0xff) << 8) | (buf[15] & 0xff);
                for (int i=24;i<24+length;i++) {
                    buf[i] = binfile.readByte();
                    bytecount++;
                prevtime = time;
                try {                       // While !end of file
                    while (true && !stopXfer) {
                        while (prevtime == time) {
                            while (pause)
                                Thread.sleep(15);
                            bos.write(buf,0,24 + length);
                            prevtime = time;
                            for (int i=0;i<24;i++) {
                                buf[i] = binfile.readByte();
                                bytecount++;
                            time = ((buf[6] & 0xff) << 24) | ((buf[7] & 0xff) << 16) | ((buf[8] & 0xff) << 8) | (buf[9] & 0xff);
                            length = ((buf[14] & 0xff) << 8) | (buf[15] & 0xff);
                            for (int i=24;i<24+length;i++) {
                                buf[i] = binfile.readByte();
                                bytecount++;
                          /*  if (rewind) {
                                binfile.reset();    <<<<Reset here>>>>>
                                rewind = false;
                            while (fastforward) {
                                binfile.skip(14);
                                bytecount+=24;
                                skipbytes[0] = binfile.readByte();
                                skipbytes[1] = binfile.readByte();
                                skiplength = ((skipbytes[0] & 0xff) << 8) | (skipbytes[1] & 0xff);
                                binfile.skip(8+skiplength);
                                bytecount+=10+length;
                                val = (double)(bytecount)/(double)(filesize);
                                updateDelayProgress((int)(val*100));
                                //System.out.println(bytecount);
                            // if times are out of order, flush buffer right away
                            if (time < prevtime || time==lastprevtime) {
                                period = 0;
                                bos.flush();
                                timecheck = prevtime;
                                prevtime = time;
                        if (lastprevtime > prevtime)
                            prevtime = lastprevtime;
                        period = (long) (time - prevtime);
                        try {
                            bos.flush();
                            stop();
                            if (period < elapsedTime || period > 750)
                                period=elapsedTime;
                            val = (double)(bytecount)/(double)(filesize);
                            updateDelayProgress((int)(val*100));
                            Thread.sleep((int)(rate*(period - elapsedTime)));
                            reset();
                            start();
                        } catch(InterruptedException ie){
                            System.out.println("Problem with thread");
                            System.exit(1);
                        prevtime = time;
                        lastprevtime = time;
                        timecheck = time;
                } catch (EOFException e) {
                } catch (SocketException s) {
                    System.out.println("Transmission ended");
                } catch (Exception e) {
                    e.printStackTrace();
                // Close input stream and display dialog with total duration of the read and transfer
                try {
                    minutes = (((System.currentTimeMillis() - begin)/1000) / 60);
                    seconds = (((System.currentTimeMillis() - begin)/1000) % 60);
                    binfile.close();
                    bos.close();
                    JOptionPane.showMessageDialog(new TBCGUI(), "Read completed in " + minutes + " minutes, " + seconds + " seconds");
                    getFrame().validate();
                } catch (Exception e) {
                    System.err.println(e);
                    e.printStackTrace();
            } catch (Exception e) {}
        }

  • Regular expressions and input streams

    Hello,
    I am trying to find a way to read characters from a stream and find matches in them with regular expressions. The problem is that the stream may contain a big amount of characters, so I can't read all of them, keep them in a big string, and then perform the searches. Is there a way to perform searches while I read the characters? I scanned the documentation of Pattern and Matcher and found nothing that can help.
    Any ideas?
    Thanks.

    Looking at the method
    public Matcher Pattern.matcher(CharSequence input);
    one could be excused for assuming that one could turn an InputStream into a CharSequence object since a 'stream' implies sequencial access and CharSequence sounds like it provides sequential access.
    This would just require the implementation of 4 method of which two (toString() and subSequence()) could probably be ignored BUT the method you wouild have to implement are charAt() and length() which imply random access rather than sequencial access!
    Using the built in regex your problem looks difficult. If you are just looking for 'equality' matches (simple searching) then you could use Knuth-Morris-Pratt algorithm or the Boyer-Moore algorithm.

Maybe you are looking for

  • Way to add a note to an email?

    Today I went to add a note to an email, however I realised whilst I can create a note, I cannot attach it to an email. It would be nice to be able to add notes to individual emails. The current note setup is little more than todo's built into mail, n

  • BT Home Hub 5 not recognising print server

    Decided to approach the forum as I have run out of ideas for fixing this problem. I originally had a BT Home Hub 3 which worked fine with my HP Designjet 500ps plus using using a wireless HP Jetdirect EW2400 print server. I then upgraded to BT Infini

  • 10.0.6 Projects/Events on External Drive Issue

    Ever since the update of 10.0.6, I seem to be having an issue with the projects that are stored on my external media. They are no longer shown in the project manager (infact one of the storage devices flashes up with the project but then it dissapear

  • How to create a transport background for an applet ?

    HI can any one tell me the solution for this ... How to create a transport background for an applet ? please help -seenu_ch

  • Duplicating images on import.

    Hi, Can anyone help me , when I import images from my camera they duplicate I had the same problem when I was using Windows 7 and thought this to be a isolated problem with windows. the import works fine but duplicates everything I import, anyone kno