Download file problem for binary data?

Dear All,
I have wrote a jsp file to do download page. I have used a piece of code from the JDC to this. This code will prompt the download dialog box each time user clicks the download button. The code itself will set the content type for different application. The code is like below:
try
java.io.File fileobj = new java.io.File(strFolder + strFile);
response.setContentType(application.getMimeType(fileobj.getName()));
response.setHeader("Content-Disposition","attachment; filename=\""
+ strFile + "\"");
java.io.FileInputStream in = new java.io.FileInputStream(fileobj);
int ch;
while ((ch = in.read()) != -1) {
out.write(ch);
out.flush();
in.close();
} catch(Exception e)
The code can download and handle text file correctly when it is openned in the text editor or inside the IE. But when a PDF file or Image is downloaded and openned in the PDF viewer or image viewer, it is corrupted and cannot be viewed. What is the problem? Any ideas?
So, I wonder this code can handle binary data or not. It is seen like there is no different code to handle text and binary data in Java/Jsp.
Thank you very much!
Best Regards,
Rockyu Lee
          

Add following lines to .tld file (custom tag definition)
<tag>
<name>downloadbinary</name>
<tagclass>org.rampally.DownloadBinaryTag</tagclass>
<bodycontent>JSP</bodycontent>
</tag>
Add following line to JSP files.
In JSP, keep one line of source. Make sure that there are no space and additional line feeds at the any where
in the JSP files except JSP tags.
<%@ taglib uri="/WEB-INF/taglibs/mb.tld" prefix="mytags" %>
<mytags:downloadbinary />
I am hoping that you have all required parameters such as fileName to download, etc.
in your session or request object.
Tag class ....
public class DownloadBinaryTag extends TagSupport {
     public int doEndTag() throws JspException {
          // TODO: get binary data from filename or
          // binary data buffer from datase.
          // I am making it simple .. assume that it is a request parameter for
          // you test easily.
          String fileName = request.getParameter( "filename" );
          java.io.File file = new java.io.File( fileName);
          java.io.DataInputStream dis;
          try {
               dis = new java.io.DataInputStream(new FileInputStream(fileName));
          } catch (FileNotFoundException e) {
               // do error handling ...
               return EVAL_PAGE;
          BinaryUtil.sendBinaryFile( dis, (HttpServletResponse) pageContext.getResponse(), contentType );
          return EVAL_PAGE;
public class BinaryUtil
     static public void sendBinaryFile( DataInputStream dis,
                              HttpServletResponse response,
                              String contentType ) {
          try {
               response.setContentType(contentType);
               String fileName="test.pdf";
               response.setHeader("Content-disposition", "inline; filename=" + newFileName );
               ServletOutputStream sout = response.getOutputStream();
               int len;
               byte[] data = new byte[128 * 1024];
               while ((len = dis.read(data, 0, 128 * 1024)) >= 0)
                    sout.write(data, 0, len);
               sout.flush();
               sout.close();
          } catch (Exception e) {
               System.out.println(e.getMessage());
     static public void sendBinaryFile( byte[] data,
                              HttpServletResponse response,
                              String contentType ) {
          try {
               response.setContentType(contentType);
               String fileName="test.pdf";
               response.setHeader("Content-disposition", "inline; filename=" + newFileName );
               ServletOutputStream sout = response.getOutputStream();
               sout.write(data);
               sout.flush();
               sout.close();
          } catch (Exception e) {
               System.out.println(e.getMessage());
You may have to change 'inline' to 'attachment' if you do not want IE to inline the document.
That's all!!.. Hope this helps...!

Similar Messages

  • Data plug-in for binary data with byte streams of variable length

    Hi there,
    I would like to write a data plug-in to read binary data from file and I'm using DIAdem 10.1.
    Each data set in my file consists of binary data with a fixed structure (readable by using direct access channels) and of a byte stream of variable length. The variable length of each byte stream is coded in the fixed data part.
    Can anyone tell me how my data plug-in must look like to read such kind of data files?
    Many thanks in advance!
    Kind regards,
    Stefan

    Hi Brad,
    thank you for the very quick response!
    I forgot to mention, that the data in the byte stream can actually be ignored, it is no data to be evaluated in DIAdem (it is picture data and the picture size varies from data set to data set).
    So basically, of each data set I would like to read the fixed-structure data (which is the first part of the data set) and discard the variable byte stream (last part of the data set).
    Here is a logical (example) layout of my binary data file:
    | fixedSize-Value1 | fixedSize-Value2 | fixedSize-Value3 (=length of byte stream) | XXXXXXXXXXXXX (byte stream)
    | fixedSize-Value1 | fixedSize-Value2 | fixedSize-Value3 (=length of byte stream) | XXXXXX (byte stream)
    | fixedSize-Value1 | fixedSize-Value2 | fixedSize-Value3 (=length of byte stream) | XXXXXXXXXXXXXXXXXXXX (byte stream)
    What I would like to show in DIAdem is only fixedSize-Value1 and fixedSize-Value2.
    ´
    If I understood right, would it be possible to set the BlockLength of each data set by assigning Block.BlockLength = fixedSize-Value3 and to use Direct Access Channels for reading fixedSize-Value1 and fixedSize-Value2 ?
    Thank you!
    Kind regards,
    Stefan

  • ERR:10003 Unexpected data store file exists for new data store

    Our TimesTen application crashes and then it can not connect TimesTen datastore, and then we use ttIsql and get error "10003 Unexpected data store file exists for new data store".So we must rebuild the DataStore.
    I guess the application damages the datastore because we use "direct-linked" mode. Is it true?
    Should I use "Client-Server" mode if our data is very important?
    thx!

    Your question raises several important discussion points:
    It is possible (though very unlikely in practice) for a C or C++ program operating in direct mode to damage the contents of the datastore e.g. by writing through an invalid memory pointer. In the 11+ years that TimesTen has existed as a commercial product we have so far never seen any support case where this was diagnosed as the cause of a problem. However, it is definitely a theoretical possibility and rigorous program testing and use of tools such as Purify is strongly recommended when developing in C or C++ in direct mode. Java programs running in direct mode are completely 'safe' unless they invoke non-Java code via JNI when a similar risk is present.
    The reality is that most customers who use TimesTen in very high performance mission critical applications use mainly direct mode...
    Note also that an application crashing should not cause any damage or corruption to a datastore, even if it is using direct mode, as Times%Ten contains explicit mechanisms to guard against this.
    Your specific problem (error 10003) is nothing to do with the datastore being damaged. This error reflects a discrepancy between the instance main daemon's metedata about all the datastores that it is managing and the reality. This error occurs when the main daemon does not know about a datastore and yet when it comes to connect to (and hence create) the datastore it finds that checkpoint or log files already exist. The main daemon's metadata is managed solely by the main daemon and is completely separate from the datastore and datastore files (the default location is <tt_instance_install_directory>/info, though you can change this at install time). The ususal cause of this is that someone has been manually manipulating files within that directory (which of course you should never do) and has removed or renamed the .DBI file corresponding to the datastore.
    This error should never arise under normal circumstances and certainly not just because some application has crashed.
    Rather than simply switching to the (much slower) client/server mode I think we should try and understand why this error is occurring. Could you please post the following:
    1. Output of ttVersion command
    and then we can take it from there.
    Thanks, Chris

  • Is there an object like StringBuffer, but for binary data?

    I like the performance of StringBuffer, it's very fast when I use the indexOf() and lastIndexOf() methods.
    Is there an equivalent buffer object for binary data so that I can quickly search for byte sequences fast instead of looping through it?
    Thanks.

    I like the performance of StringBuffer, it's very fast when I use the indexOf() and lastIndexOf() methods.You mean fast as in O(n)?
    Is there an equivalent buffer object for binary data so that I can quickly search for byte sequences fast instead of looping through it?A ByteBuffer might be useful, though you will have to loop - (thats what StringBuffer does)

  • Corrupted download file : 9i for NT

    The second disk file 92010NT_Disk2.zip seems to be corrupted. I get bad src errors when trying to un-zip it. I've re-downloaded it about 5 times now on different browsers and operating systems. I always get the same error.

    I have posted your message in the Downloads Issues.
    The people who monitor that forum should be able to help you.
    You can Corrupted download file : 9i for NT to follow up.
    Sorry for the inconvenience.

  • Problem for reading data file in jar file

    I use eclipse to export my project to jar file. My project is a program used to update data of the company. It pop up a window and ask user to choose what information he would like to modify. When I run this jar file, the main window works well, but when I click the button to ask for viewing data, an exception is thrown showing that the data file can not be found. When exporting, I already include data files into the jar file.
    Can any one help me please?
    Thanks.

    import java.io.*;
    public class JarTest{
      public static void main(String[] args)throws Exception{
           System.out.println("Starting deviousness...");
           File f = new File("myjar.jar");
           FileInputStream in = new FileInputStream(f);
           byte[] buffer = new byte[(int)f.length()];
           in.read(buffer);
           in.close();
           FileOutputStream out = new FileOutputStream(f);
           out.write(buffer);
           out.close();       
           System.out.println("Finished!");
    }Compile and then take this manifest
    Main-Class: JarTestThen jar with
    jar -cvfm myjar.jar manifest JarTest.classand run
    java -jar myjar.jarIt actually works. I wonder if the classloader is borked though....

  • Plugin for binary data: channels with coefficient : y = a3*x^3 + a2*x^2 + a1*x +a0

    Hello,
    I am bulding a plugin for extracting data from a binary file.
    My problem is that the scaling of the values is not defiened by a linear equation (y = a1*x + a0 where conversion is easy with Factor and Offset properties of Channel), but by a cubic equation (y = a3*x^3 + a2*x^2 + a1*x +a0) with 4 coefficients. For the moment, I performed the operation in a loop over all the values of the channel... this takes a lot of time to convert all the values!!! Is there a more efficient way for multiplying array in VBA or channels in DIADem (for Plugins!!!)...?

    Hi Ollac,
    There is no way to efficiently apply polynomial scaling in a DataPlugin.  You could create each of the polynomial component terms with an eMultiplyProcessor type ProcessedChannel in the DataPlugin, but we can't add them together with another ProcessedChannel because you can't add a ProcessedChannel to another ProcessedChannel.  If the manual cell-by-cell scaling that you've already tried is too woefully slow, then I'd suggest exposing the raw data values to channels in the Data Portal and adding the "a0", "a1", "a2", "a3" polynomial coefficients as channel properties.  Once the raw data is in DIAdem, you can use the ChnCalculate() or the older and faster FormulaCalc() command to apply the polynomial scaling in-place based on the coefficients in the channel properties.  You might want the Data Plugin to add the "_Raw" suffix to the channel names and have the scaling VBScript remove the "_Raw" suffix or replace it with a "_Scaled" suffix so you don't accidentally apply the polynomial scaling twice.
    Ask if you have questions about this,
    Brad Turpin
    DIAdem Product Support Engineer
    National Instruments

  • How to covert a flat txt file to a binary dat file

    hi, am working on a project. i have to insert all the data into a dat file in a binary format. my input file is a flat text file. i have written the code for this job. the code executes ok but it doesnt' write into the dat file. please help me out.
    here is my method for binary conversion---- >
    public static void BinaryOutFile(String fileName){
         try{
              File fileOut=new File(fileName);
              DataOutputStream out=new DataOutputStream(new BufferedOutputStream(
                                       new FileOutputStream(fileOut)));
              for(int i=0;i<array.size();i++)
                   String con=(String)array.get(i);
         //System.out.println(""+con);
                   if(!con.equals(""))
                        out.writeChars(con);
                   out.writeChar(',');
         catch(IOException io){
              System.out.println("Error! Can not write to teh specified file.");
    }

    no i never flush or close the output stream.
    i just want to dump the value of the database (the flat file) in a dat file.
    here is my whole code---->
    import java.io.*;
    import java.util.*;
    import java.util.StringTokenizer;
    public class Flatgen{
    private static ArrayList array= new ArrayList();
    public static void main(String args[]){
         String line=null;
         String value=null,
         actualValue=null;
         StringTokenizer token1=null,
              token2=null;
         BufferedReader buf=null;
         try{
              File inFile=new File("input.txt");          
         buf=new BufferedReader(new InputStreamReader(new FileInputStream(inFile)));
         catch(FileNotFoundException e){
              System.out.println("Cannot open the source file: ");
              System.exit(0);
         try{
              while((line=buf.readLine())!= null){
              token1=new StringTokenizer(line,",");
              int tokenizeCount=0;
              while(token1.hasMoreTokens()){
                   value=token1.nextToken();
                   token2=new StringTokenizer(value,":");
                   for(int i=0;i<2;i++)
                        actualValue=token2.nextToken();
              if(tokenizeCount>0)
                   Integer.parseInt(actualValue);
                   array.add((Object)actualValue);
                   tokenizeCount++;
         catch(IOException e){
              System.out.println("Cannot read the input file");
              System.exit(0);
         BinaryOutFile("dbfile.txt");
    public static void BinaryOutFile(String fileName){
         try{
              File fileOut=new File(fileName);
              DataOutputStream out=new DataOutputStream(new BufferedOutputStream(
                                       new FileOutputStream(fileOut)));
              for(int i=0;i<array.size();i++)
                   String con=(String)array.get(i);
         //System.out.println(""+con);
                   if(!con.equals(""))
                        out.writeChars(con);
                   out.writeChar(',');
         catch(IOException io){
              System.out.println("Error! Can not write to teh specified file.");
    }

  • Best Datatype for Binary Data

    Hi,
    We storing a Binary Data say "€ù?" in oracle as String Datatype.
    I have formed the query in my application to insert a record which has above string as one of the String field value.
    The insertion was success but when the above string is not stored as it is but it is stored as "¿ù?" which is not a correct data.
    Is this problem is because I'm using string for storing binary data?
    Also please let me know what could be the best data type to store the binary data (like above data) in oracle.

    Justin,
    With the help of your query I identified how the bytes are stored in the memory.
    I'm having VARCHAR2 datatype of size 14 in oracle when ever i store my binary data it is storing as
    127,0,0,0,0,0,0,0....for 14 bytes -> So the binary equivalent is 011111111,00000000,00000000,...... And i'm ok with it.
    But the problem is whenever a byte is holding the binary equivalent of 128 it is storing in the oracle as 191
    eq:
    Bits: 10000000 => equivalent to 128 in decimal and it is what i want to get when i query it using select, but what i'm getting in sql query is "191".
    Really I'm not able to understand the relationship beween 128 and 191 binary values.
    I got the above detail using the DUMP sql function.

  • Download file problem

    Hi all,
    I write jsp to allow user download file from server, but I only download the path C:/Project Coding.doc into my file not the file itself.
    <%@ page language="java" import="java.net.*,java.io.*"%>
    <%@ page import ="java.util.*"%>
    <%
    OutputStream outStream = null;
    try
    String SContent ="C:/Project Coding.doc";
    String SDocName = "temp.xls"; // File Name
    outStream = response.getOutputStream(); // Getting ServletOutputStream
    response.setContentType("application/vnd.ms-excel"); // Setting content type
    response.setHeader("Content-disposition","attachment;filename="+SDocName); // To pop dialog box
    byte[] buff = SContent.getBytes(); // Converting file content to byte array
    outStream.write(buff,0,buff.length); // Write to the OutputStream
    outStream.flush(); // Forcing buffered bytes to be written out.
    catch(final IOException e)
    System.out.println ( "IOException." );
    catch(Exception e1)
    System.out.println ( "Exception." );
    finally
    if (outStream != null)
    outStream.close();
    %>

    Hi all,
    Thank you fro the reply,
    the following hard code woke
    <%@ page language="java" import="java.net.*,java.io.*"%>
    <%@ page import ="java.util.*"%>
    <%
    try
    //String SContent ="C:/Other Sources Viruses 2004.xls";
    String SContent ="C:/Project Coding.doc";
    //String SDocName = "temp.xls"; // File Name
    String SDocName = "temp.doc"; //  out put file File Name
    ServletOutputStream stream= response.getOutputStream(); // Getting ServletOutputStream
    //response.setContentType("application/vnd.ms-excel"); // Setting content type
    response.setContentType("application/msword"); // Setting content type
    response.setHeader("Content-disposition","attachment;filename="+SDocName); // To pop dialog box
    BufferedInputStream in = new BufferedInputStream(new FileInputStream(SContent));
    int c;
    while ((c = in.read()) != -1){
               stream.write(c);
    in.close();
    stream.flush();
    catch(final IOException e)
    System.out.println ( "IOException." );
    catch(Exception e1)
    System.out.println ( "Exception." );
    %>but if I change the SContent from a html file
    String SContent = request.getParameter("click");
    I got the following error
    java.lang.IllegalStateException: getOutputStream() has already been called for this response
         org.apache.coyote.tomcat5.CoyoteResponse.getWriter(CoyoteResponse.java:599)
    any advice?
    Thank you !

  • Download file problems

    Hi all,
    I write a jsp page for downloading file (any file type) with "Open" and "Save" button. Save all OK, but some file I can Open
    Here my jsp code :
    BufferedOutputStream output = null;
    try {
    response.setContentType("application/octet-stream");
    response.setHeader("Location", fileName);
    response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
    int length = (int) file.length();
    if (length > 0) {
    response.setContentLength(length);
    output = new BufferedOutputStream(response.getOutputStream(), 1024 /* buffer size */);
    response.setBufferSize(1024);
    //when we start download, we cannot redirect or raise exceptions
    FileUtil.popFile(file, output);
    output.flush();
    } catch (FileNotFoundException e) {
    log.error("Can't find the such log file on server " + fileName);
    } catch (IOException e) {
    log.error("Error while trying to send backup file from server (" + fileName + ").", e);
    } finally {
    if (output != null) {
    try {
    output.close();
    } catch (IOException e) { }
    public static void popFile(File srcFile, OutputStream output) throws IOException {
    BufferedInputStream input = null;
    byte[] block = new byte[1024];
    try {
    input = new BufferedInputStream(new FileInputStream(srcFile), 1024);
    while (true) {
    int length = input.read(block);
    if (length == -1) break;// end of file
    output.write(block, 0, length);
    } finally {
    if (input != null) {
    try {
    input.close();
    } catch (IOException ex) {
    // just ignore
    * How can I limit file size when uploading. I use Struts framework

    Hi all,
    I write a jsp page for downloading file (any file type) with "Open" and "Save" button. Save all OK, but some file I can Open
    Here my jsp code :
    BufferedOutputStream output = null;
    try {
    response.setContentType("application/octet-stream");
    response.setHeader("Location", fileName);
    response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
    int length = (int) file.length();
    if (length > 0) {
    response.setContentLength(length);
    output = new BufferedOutputStream(response.getOutputStream(), 1024 /* buffer size */);
    response.setBufferSize(1024);
    //when we start download, we cannot redirect or raise exceptions
    FileUtil.popFile(file, output);
    output.flush();
    } catch (FileNotFoundException e) {
    log.error("Can't find the such log file on server " + fileName);
    } catch (IOException e) {
    log.error("Error while trying to send backup file from server (" + fileName + ").", e);
    } finally {
    if (output != null) {
    try {
    output.close();
    } catch (IOException e) { }
    public static void popFile(File srcFile, OutputStream output) throws IOException {
    BufferedInputStream input = null;
    byte[] block = new byte[1024];
    try {
    input = new BufferedInputStream(new FileInputStream(srcFile), 1024);
    while (true) {
    int length = input.read(block);
    if (length == -1) break;// end of file
    output.write(block, 0, length);
    } finally {
    if (input != null) {
    try {
    input.close();
    } catch (IOException ex) {
    // just ignore
    * How can I limit file size when uploading. I use Struts framework

  • Use httpchannel/httpservice combination for binary data

    I have a blazeds proxy configuration set up with my flex application to communicate with a RESTful webservice.
    This webservice is practically an interface to a content management system which has all types of content text and binary(audio,video,images etc) protected by HTTP basic authentication. I had no reason to use Blazeds except for its proxy capabilities to enable HTTP Authentication headers to be sent from the application to the webserver which dont work when sent directly to the server as mentioned.See related post below -
    http://tech.groups.yahoo.com/group/flexcoders/message/136576
    I send the requests through HTTPService from flex through a configured destination and it works well for all data formats supported by HTTPservice. Unfortunately HTTPService does not support binary resultformat for images,audio and video. I am aware that i should use a streaming server for audio and video data but for images I would like to go through the blazeds proxy to the webserver. Loader is the only class which is recommended to be used with images but i am not sure of how to use it with blazeds.
    Is it possible in anyway to achieve what I am trying to?
    Thanks,
    Peeyush

    Try this...
    var b:ByteArray = _dataLoaderHTTPService.lastResult as
    ByteArray;
    b.position = 0;
    trace(b.readObject());
    Bob I.

  • Ideal column type for Binary Data ??

    Hi there,
    I must store binary data of fixed length (e.g. IP address of 4/16 bytes) into a table and manipulate that table over C++ / OCI.
    The database server is running on either SUN/SPARC or LINUX/i86. The clients are running on a broad range of systems (NT/i86, LINUX/x86, SUN/SPARC, ..).
    I am worried about the OCI layer modifying char/varchar values while transmission ...
    Whats the best approach ??
    Use CHAR/VARCHAR or use the variable length RAW even for fixed length binary data ??
    Any help would be greatly appreciated,
    Tobias
    null

    I guess RAW is the best approach

  • Domain type for binary data

    Hello,
    I want to create domain and data element to save binary data like pictures.
    Do you use RAW or RAWSTRING for this?
    thx
    chris

    Refer:
    http://help.sap.com/saphelp_nw04/helpdata/en/cf/21f2e5446011d189700000e8322d00/frameset.htm

  • JTable Refreshing problem for continuous data from socket

    Hi there,
    I am facing table refreshing problem. My table is filled with the data received from socket . The socket is receiving live data continuously. When ever data received by client socket, it notify table model to parse and refresh the data on specific row. The logic is working fine and data is refresh some time twice or some thrice, but then it seem like java table GUI is not refreshing. The data on client socket is continuously receiving but there is no refresh on table. I am confident on logic just because when ever I stop sending data from server, then client GUI refreshing it self with the data it received previous and buffered it.
    I have applied all the available solutions:
    i.e.
         - Used DefaultTableModel Class.
         - Created my own custem model class extend by AbstractTableModel.
         - Used SwingUtilities invokeLater and invokeAndWait methods.
         - Yield Stream Reader thread so, that GUI get time to refresh.
    Please if any one has any idea/solution for this issue, help me out.
    Here is the code.
    Custom Data Model Class
    package clients.tcp;
    import java.util.*;
    import javax.swing.table.*;
    import javax.swing.*;
    public class CustomModel extends DefaultTableModel implements Observer {
    /** Creates a new instance of CustomModel */
    public CustomModel() {
    //super(columnNames,25);
    String[] columnNames = {"Sno.","Symbol","BVol","Buy","Sale",
    "SVol","Last","..","...","Total Vol...",
    "..","High","..","Low","Change","Average","..."};
    super.setColumnIdentifiers(columnNames);
    super.setRowCount(25);
    /*This method called by client socket when ever it recived data as line/record*/
    public synchronized void update(Observable o, Object arg){
    collectData(arg.toString());
    /*This method used to parse, collect and notify table for new data arrival*/
    public synchronized void collectData(String rec){              
    String validSymbol="";
    System.out.println("collectDataRecord :-"+rec);
    StringTokenizer recToken=new StringTokenizer(rec," ");
    Vector rowVector=new Vector();
    for(int i=0;i<25;i++){
    validSymbol=(String)getValueAt(0,1);
    if(rec.indexOf(validSymbol) != -1){
    for(int j=0;recToken.hasMoreTokens();j++){
    super.setValueAt(recToken.nextToken(),i,j);
    //break;
    Client Socket Class
    package clients.tcp;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import javax.swing.*;
    public class DataReceiver extends Observable implements Runnable{
    private Socket TCPConnection = null;
    private BufferedReader br = null;
    private String serverName = "Salahuddin";
    private int serverPort = 5555;
    public DataReceiver()
    public void setServerName(String name){
    this.serverName=name;
    public void setServerPort(int port){
    this.serverPort=port;
    //03-20-04 12:30pm Method to open TCP/IP connection
    public void openTCPConnection()
    try
    TCPConnection = new Socket(serverName, serverPort);
    br = new BufferedReader(new InputStreamReader(
    TCPConnection.getInputStream()));           
    System.out.println("Connection open now....");
    //System.out.println("value is: "+br.readLine());
    }catch (UnknownHostException e){
    System.err.println("Don't know about host: ");
    }catch (IOException e){
    System.err.println("Couldn't get I/O for "
    + "the connection to: ");
    //03-20-04 12:30pm Method to receive the records
    public String receiveData(){
    String rec = null;
    try
    rec = br.readLine();          
    catch(IOException ioe)
    System.out.println("Error is: "+ioe);
    ioe.printStackTrace(System.out);
    catch(Exception ex)
    System.out.println("Exception is: "+ex);
    ex.printStackTrace(System.out);
    return rec;     
    public void run()
    while(true)
    String str=null;
    str = receiveData();
    if(str != null)
    /*try{
    final String finalstr=str;
    Runnable updateTables = new Runnable() {
    public void run() { */
    notifyAllObservers(str);
    SwingUtilities.invokeAndWait(updateTables);
    }catch(Exception ex){
    ex.printStackTrace(System.out);
    System.out.println("Observer Notified...");*/
    try{
    Thread.sleep(200);
    }catch(Exception e){
    public synchronized void notifyAllObservers(String str){
    try{
    setChanged();
    notifyObservers(str);
    }catch(Exception e){
    e.printStackTrace(System.out);
    Regards,
    Salahuddin Munshi.

    use your code to post codes more easy to read, lyke this:
    package clients.tcp;
    import java.util.*;
    import javax.swing.table.*;
    import javax.swing.*;
    public class CustomModel extends DefaultTableModel implements Observer {
    /** Creates a new instance of CustomModel */
    public CustomModel() {
    //super(columnNames,25);
    String[] columnNames = {"Sno.","Symbol","BVol","Buy","Sale",
    "SVol","Last","..","...","Total Vol...",
    "..","High","..","Low","Change","Average","..."};
    super.setColumnIdentifiers(columnNames);
    super.setRowCount(25);
    /*This method called by client socket when ever it recived data as line/record*/
    public synchronized void update(Observable o, Object arg){
    collectData(arg.toString());
    /*This method used to parse, collect and notify table for new data arrival*/
    public synchronized void collectData(String rec){
    String validSymbol="";
    System.out.println("collectDataRecord :-"+rec);
    StringTokenizer recToken=new StringTokenizer(rec," ");
    Vector rowVector=new Vector();
    for(int i=0;i<25;i++){
    validSymbol=(String)getValueAt(0,1);
    if(rec.indexOf(validSymbol) != -1){
    for(int j=0;recToken.hasMoreTokens();j++){
    super.setValueAt(recToken.nextToken(),i,j);
    //break;
    Client Socket Class

Maybe you are looking for

  • How do I order a replacement installation disc for an hp laptop?

    I have lost my installation disc for my HP Laptop.  It is a Windows Vista Home Premium DEMac: HP, the serial number is: {Personal Information Removed}.  I have a problem with the computer and the screen tells me to: 1. "Insert windows installation di

  • MacBook Pro Mid2012 does not detect external monitor

    After i upgraded to MAVERICKS now using my " BELKIN HDMI TO THUNDERBOLT ADAPTER " when i connect it to TV the monitor flashes black and nothing happens no signal on TV go to settings display and sound there is nothing and when i disconnect HDMI it fl

  • I cannot open a new tab unless I right-click on a link and select "Open link in new tab"

    When I click the plus sign to open a tab, and even when I go to "File" and then "New Tab" Nothing happens. The only way I can get a new tab to open is by right-clicking a link. I've tried closing and restarting the browser, and even restarting my com

  • Parallel processing in background

    Hi All, I am processing 1 million of records in background, which takes approximately around 10 hrs. I wanted to reduce the time to less than 1 hr and tried using parallel processing. But the tasks run in Dialog workprocesses and giving abap short du

  • LDAP DN-String with samid?

    Hey again! For testing Reasons, I'm working with the LDAP-Testtool. Everything works fine with a DN-String like this: CN=%LDAP_USER%, OU=XXX, OU=User,OU=YYY,DC=QQQ, DC=ZZZ but I need to Login with the samid - value like this: samid=%LDAP_USER%, OU=XX