FileInputStream Question

Hi All
I need some information on using a relative path in a FileInputStream.
I want to use the following code:
JasperReport template = JasperManager.loadReport (new FileInputStream ("reports//Main.jasper"));to reference a file in the reports directory in the directory where my class files are located. How do I do this without using an absolute path.
Hope to hear from you soon.
Regards,
C

I'm feeling like a nice guy, so I'm going to post some code that I use quite often for doing this sort of thing.
The class is below. Here's how I use it to set up logging using log4j (I use the LOGROOT environment variable in my log4j.properties to help define where the log files should actually get generated):
     static private void configureLoggers() throws MaestroStartupFailedException{
          File appRoot = ClassUtilities.getClassPathComponentFile(MaestroApp.class);
          if (appRoot.getName().toLowerCase().endsWith(".jar")) // if we are in a JAR, then the app path is going to be below us a couple of levels
               appRoot = appRoot.getParentFile().getParentFile(); // this will drop us to the lib, then to the app base path
          File logRoot = new File(appRoot, "logs/");
          File log4jPropFile = new File(logRoot, "log4j.properties");
          if (!log4jPropFile.exists())
               throw new Exception("Unable to find logging definition file at " + log4jPropFile);
          System.setProperty("LOGROOT", logRoot.getAbsolutePath());
          System.out.println("Logging using properties from " + log4jPropFile.getAbsolutePath());
          System.out.println("LOGROOT set to " + System.getProperty("LOGROOT"));
          PropertyConfigurator.configureAndWatch(log4jPropFile.getAbsolutePath(), 60000);
     }And here's the utility class (ClassUtilities) implementation
package com.trumpetinc.util;
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
* @author Kevin Day
* Trumpet, Inc.
* www.trumpetinc.com
* Use this code at your own risk - I don't claim that it actually works,
* will not be held liable for how you choose to use it, etc..., etc...
* If you choose to use this class, please keep the entire thing together and
* leave these comments at the top.
public class ClassUtilities {
      * Constructor for ClassUtilities.
     private ClassUtilities() {
          super();
        * Returns the classpath component from which a class with the
        * supplied name was loaded, or <code>null</code> if a class with
        * the supplied name could not be loaded.  The supplied {@link
        * java.lang.ClassLoader <code>ClassLoader</code>} is used, unless
        * it is <code>null</code>, in which case the system classloader is
        * used instead.
        * @param className the name of a class to load
        * @param loader a {@link java.lang.ClassLoader
        * <code>ClassLoader</code>} to use to attempt to load the class
        * specified by <code>className</code>; if <code>null</code> the
     system
        * classloader will be used instead
        * @return a {@link java.net.URL <code>URL</code>} to the classpath
        * component that the class corresponding to the supplied name
        * was loaded from, or <code>null</code> if no such class was
        * found
        * @exception org.gjt.ljn.core.NullArgumentException if
        * <code>className</code> is <code>null</code>
       public static final URL getClassPathComponentURL(Class aClass,
                                      ClassLoader loader)
          if (aClass == null) {
            return null;
          String resourceName = aClass.getName().replace('.', '/') + ".class";
          return getClassPathComponentURL(resourceName, loader);
      * Returns a File pointing to the ROOT of the resource specified.  If the resource is
      * in a .jar file, the folder that the jar file is located in is returned.  If the
      * resource is located in a directory structure beneath a classpath folder, then the
      * classpath folder will be returned.
      * @param resourceName
      * @return File
     public static final File getClassPathComponentRoot(String resourceName){
          try {
               File aRoot = new File(new URI(ClassUtilities.getClassPathComponentURL(resourceName, null).toExternalForm()));
               if (aRoot.isDirectory()) return aRoot;
               return aRoot.getParentFile();
          } catch (URISyntaxException e) {
               return null;
     public static final File getClassPathComponentRoot(Class aClass){
          try {
               File aRoot = new File(new URI(ClassUtilities.getClassPathComponentURL(aClass, null).toExternalForm()));
               if (aRoot.isDirectory()) return aRoot;
               return aRoot.getParentFile();
          } catch (URISyntaxException e) {
               return null;
     public static final URL getClassPathComponentURL(String resourceName,
                                    ClassLoader loader){
                                        URL resource = null;
               if (loader == null) {
                 resource = ClassLoader.getSystemResource(resourceName);
               } else {   resource = loader.getResource(resourceName);
               if (resource == null) {
                 return null;
               String resourceURLString = resource.toString();
               if (resourceURLString == null) {
                 // don't think this could ever happen
                 return null;
               String temp =
                    resourceURLString.substring(0, resourceURLString.indexOf(resourceName)     - 1);
               if (temp.startsWith("jar:")) {
                 temp = temp.substring("jar:".length(), temp.length() - 1);
               try {
                 return new URL(temp);
               } catch (Exception anything) {
                 throw new Error("This should never happen! (" +
                           anything.toString() + ")");
     public static final File getClassPathComponentFile(Object o){
          try {
               Class c = o instanceof Class ? (Class)o : o.getClass();
               return new File(new URI(ClassUtilities.getClassPathComponentURL(c, null).toExternalForm()));
          } catch (URISyntaxException e) {
               return null;
     public static void printSerialVersionUID(Class c){
          long verID = java.io.ObjectStreamClass.lookup(c).getSerialVersionUID();
          System.out.println(c + "\n==========================");
          System.out.println("     static final long serialVersionUID = " + verID + "L;\n");
}

Similar Messages

  • GUI Quiz - cannot get it to work (runtime error)

    i have a runtime error that says "Exception in thread "main" java.lang.NoClassDefFoundError: Quiz" can anyone tell me whats wrong with my code?
    the code is the following and i need to read in a question and display it graphically so the user can answer...
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    import java.io.*;
    public class Quiz implements ActionListener
         // To use JRadioButtons effectively, you need a ButtonGroup.  See Section
         // 5.12 in the text for more details on JRadioButtons.
         private ButtonGroup [] theGroups;
         // Note that the choices, counts and labels are all arrays.  These arrays
         // will allow us to more easily access the data, and will allow us to have
         // an arbitrary number of each of these.  The size of the arrays are
         // determined in the constructor.
         private JRadioButton [] theChoices;
         private int [] guessedAnswer;
         private JLabel [] answerLabels;
         private String greeting = "Welcome to the Music Poll!  Please select your favorite band";
         private JFrame theWindow;
         private JLabel intro;
         private JPanel radioPanel;
         private static Font font1 = new Font("Times", Font.BOLD, 16);
         private static Font font2 = new Font("Times", Font.ITALIC, 20);
         private JButton reset;
         public Quiz(String [] data)
              // Much of the initialization below are things we have seen before.
              theWindow = new JFrame("Quiz v. 1.0");
              Container c = theWindow.getContentPane();
              intro = new JLabel(greeting);
              intro.setFont(font2);
              theGroups = new ButtonGroup[numQuestions];
              theChoices = new JRadioButton[data.length];
              theCounts = new int[data.length];
              countLabels = new JLabel[data.length];
              radioPanel = new JPanel();
              radioPanel.setLayout(new GridLayout(data.length+1, 2));
              JLabel answerLabel = new JLabel("Answers");
              countLabel.setHorizontalAlignment(SwingConstants.CENTER);
              countLabel.setFont(font1);
              JLabel questionLabel = new JLabel("Question");
              questionLabel.setFont(font1);
              radioPanel.add(answerLabel);
              radioPanel.add(questionLabel);
              for (int i = 0; i < data.length; i++)
                   theChoices[i] = new JRadioButton(data);
                   theChoices[i].setHorizontalAlignment(SwingConstants.LEFT);
                   // See the GuessListener class below for more information about it.
                   theChoices[i].addActionListener(new GuessListener(i));
                   guessedAnswer[i] = 0;
                   answerLabels[i] = new JLabel("" + guessedAnswer[i]);
                   answerLabels[i].setHorizontalAlignment(SwingConstants.CENTER);
                   group.add(theChoices[i]);
                   radioPanel.add(answerLabels[i]);
                   radioPanel.add(theChoices[i]);
              reset = new JButton("Next Question");
              reset.addActionListener(this);
              c.add(intro, BorderLayout.NORTH);
              c.add(radioPanel, BorderLayout.CENTER);
              c.add(reset, BorderLayout.SOUTH);
              theWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              theWindow.pack();
              theWindow.setVisible(true);
         // actionPerformed to reset the counts -- this is the ActionListener
         // implementation of the main class.
         public void actionPerformed(ActionEvent e)
              for (int i = 0; i < answerLabels.length; i++)
                   guessedAnswer[i] = 0;
                   answerLabels[i].setText("" + guessedAnswer[i]);
         // This ActionListener is used to update the count of the band that
         // was selected by the user. Rather than having a single object with
         // a test to see which JRadioButton was pressed, we instead assign a
         // separate instance of the GuessListener for each JRadioButton. In
         // order to know which count and label to update, we need to know the
         // index. This can be easily done with a constructor to tailor each
         // instance of the listener to the JRadioButton it is listening to.
         private class GuessListener implements ActionListener
              private int index;
              public GuessListener(int i)
                   index = i;
              public void actionPerformed(ActionEvent e)
                   guessedAnswer[index]++;
                   answerLabels[index].setText("" + guessedAnswer[index]);
         public static void main(String [] args)
              // Try adding and/or removing strings from the options array
              // and see how the window changes.
              int numQuestions;
              int numAns;
              int corrAns;
              String s;
              Scanner fileScan = new Scanner(new FileInputStream("Questions.txt"));
              numQuestions = filescan.nextInt();
              qs = new Question[numQuestions];
              for(int i = 0; i < numQuestions)
                   String s = filescan.next();
                   int numAns = filescan.nextInt();
                   String [theAns] = new String[numAns];
                   for(int j = 0; j < numAns; j++)
                        theAns[j] = new String(filescan.next());
                   int corrAns = filescan.nextInt();
                   ques[i] = new Question(s, theAns, corrAns);
              new Quiz(ques);
    the following is my question class to form each question and its answer...
    import java.util.*;
    import java.io.*;
    public class Question
         String ask;
         String [] answer;
         int correctAnswer;
         public Question(String q, String [] ans, int correct)
              ask = new String(q);
              answer = new String[ans.length];
              for (int i = 0; i < ans.length; i++)
                   answer[i] = new String(ans[i));
              correctAnswer = correct;
              return(ask, answer, correctAnswer);
    }thanks

    Are you sure this compiles? You define an array of Questions (not
    declared anywhere) as "qs" and later appear to use is as "ques".
    The braces in the main method are unmatched.
    If it doesn't compile, you won't get any runtime errors (because it
    won't run) but java will complain that the Quiz class doesn't exist
    (because it doesn't).

  • Question Regarding FileInputStream

    Hi all,
    My requirement is to find the label names form the JSPs so i have done it but the problem i am facing is that
    File f = new File("D:\jsps\filename.jsp");
    FileInputStream fis = new FileInputStream(fis);
    but if i pass it like that it will not work on the other system if we have stored the file in another path so i need the help of how to get the path of the file dynamically. That is can we get the entire path of the file by just passing the file name.
    Thank u for all
    K.Kiran Kumar

    Maybe something like:
    File f = new File(System.getProperty("user.dir") + File.separator + filename.jsp);
    This set the location of the filename.jsp file to a place on the filesystem that is from where the java was run.
    To allow you program to work with differing directories on different systems you would be better having a properties file that added itself into the System Properties so that in your code you could call something like
    File f = new File(System.getProperty("myFiles.dir") + File.separator + filename.jsp);
    On one system the properties file would have
    myFiles.dir = "d:\jsps"
    And on the other system you can change this to the correct location for the jsps.
    e.g. myFiled.dir = "/usr/local/jsp"

  • Efficiency Question: Simple Java DC vs Used WD Component

    Hello guys,
    The scenario is - I want to call a function that returns a FileInputStream object so I can process it on my WD view. I can think of two approaches - one is to simply write a simple Java DC that does so and just use it as a used DC so I can call the functionality from there. Or create another WD DC that exposes the value (as binary) via component interface.
    I'm leaning on the simple Java DC approach - its easier to create. But I'm just curious on what would be the Pro-side (if there's any) if I use the WD Component interface approach? Is there a plus for the efficiency? (Though I doubt) Or is it just a 'best/recommended practice' approach?
    Thanks!
    Regards,
    Jan

    Hi Jan
    >one is to simply write a simple Java DC that does so and just use it as a used DC so I can call the functionality from there
    Implemented Java  API for the purpose mentioned in your question is the right way, I think. The Java API can be even located in the same WebDynpro DC as your WebDynpro components. There is not strongly necessity to put it into separate Java DC.
    >Or create another WD DC that exposes the value (as binary) via component interface
    You should not do this because in general WD components' purpose is UI, not API. Implementing WD component without any UI, but with some component interface has very-very restricted use cases. Such WD component shall only be a choice in the cases when the API is WebDynpro based and if you have to strongly use WebDynpro Runtime API in order to implement your own API.
    If your API does not require WebDynpro Runtime API invocations or anything else related to WebDynpro then your choice is simple Java API.
    >But I'm just curious on what would be the Pro-side (if there's any) if I use the WD Component interface approach? Is there a plus for the efficiency?
    No. Performance will be better in simple Java API then in WebDynpro component interface. The reason is the API will not pass thought heavy WebDynpro engine.
    BR, Siarhei

  • Question about JSP, XSLT and JDOM

    hi, folks. Let's say within page1.jsp, i have <jsp:include page="page2.jsp" flush="true"> On the other hand, i have a servlet helper class which queries the database, then converts the ResultSet object into a JDOM Document object. My question is i want to make the transformed output of the JDOM Document and XSLT template to be a partial content of the page2.jsp page. How can i get this done properly? I have no problem of doing the transformation, but just dont know how to concatenate the output with the rest content of page2.jsp. Hope i clearly explained the question. Any advice is greatly appreciated.
    //code fragment on page2.jsp
    <td valign="top" width="788">
        <font size="3"><br>  
            <p>
           //i want put the transformed results here
           </p>
         </font>
    </td>

    this is a fragment of my testing program, which transform direct to response output stream. but i dont want put this bounch of java code within page2.jsp. do i some other way around to get it done?
    Document myDocument = createDocument();
                   TransformerFactory tFactory = TransformerFactory.newInstance();
                // Make the input sources for the XML and XSLT documents
                org.jdom.output.DOMOutputter outputter = new org.jdom.output.DOMOutputter();
                org.w3c.dom.Document domDocument = outputter.output(myDocument);
                javax.xml.transform.Source xmlSource = new javax.xml.transform.dom.DOMSource(domDocument);
                StreamSource xsltSource = new StreamSource(new FileInputStream("d:/tomcat/webapps/project/car.xsl"));
            //Make the output result for the finished document
                StreamResult xmlResult = new StreamResult(response.getOutputStream());
                //StreamResult xmlResult = new StreamResult(System.out);
            //Get a XSLT transformer
            Transformer transformer = tFactory.newTransformer(xsltSource);
            //do the transform
                transformer.transform(xmlSource, xmlResult);

  • General question about webservices

    I hava a file "Test.java" (which attempts to test a webservice) and a XML-File.
    I compiled the Test-class successfully and now I'm wondering what are the next
    steps to be able to send a request to the webservice and get a response.
    I know that I will need to install Apache Axis (?). But I have no idea how to go on.
    What is with the Test.class? I'll have to pack it somehow, I suppose.
    Sorry if my question's too stupid. I'm a beginner with Java and all those web- and xml-things are very confusing. :o(
    The Test.java:
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.net.URL;
    import java.security.Security;
    import org.apache.axis.Constants;
    import org.apache.axis.client.Call;
    import org.apache.axis.client.Service;
    import org.apache.axis.encoding.XMLType;
    import org.xml.sax.ContentHandler;
    import org.xml.sax.InputSource;
    import org.xml.sax.XMLReader;
    import org.xml.sax.helpers.XMLReaderFactory;
    import javax.xml.rpc.ParameterMode;
    public class Test
    public static void main(String [] args) throws Exception {
         try {
              runIt();
         } catch(Exception e) {
              e.printStackTrace();
    private static void runIt() throws Exception {
         System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");
         Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
         System.setProperty("javax.net.ssl.trustStore","C:/java/olliclientkeystore");
         String ret = "";
         String endpoint = "https://whatever";
         Service service;
         Call call;
         for (int i = 0; i <= 8; i++) {
         switch(i) {
              case 0:     System.out.println("Case 0");
              service = new Service();
              call = (Call) service.createCall();
              call.setTargetEndpointAddress(new URL(endpoint));
              call.setOperationName("abc");
              call.addParameter("x1", Constants.XSD_STRING, ParameterMode.IN);
              call.addParameter("x2", Constants.XSD_STRING, ParameterMode.IN);
              call.addParameter("x3", Constants.XSD_STRING, ParameterMode.IN);
              call.addParameter("x4", Constants.XSD_INT, ParameterMode.IN);
              call.setReturnType( XMLType.XSD_STRING );
              call.setUsername("xyz");
              call.setPassword("zyx");
              ret = (String) call.invoke(new Object[] {"abc",null,null, new int[] {1,3,5}});
              break;
              case 1:     System.out.println("Case 1");
              case 8:     System.out.println("Case 8");
                        service = new Service();
                        call = (Call) service.createCall();
                        call.setTargetEndpointAddress(new URL(endpoint));
                        call.setOperationName("def");
                        call.setReturnType( XMLType.XSD_STRING );
                        call.setUsername("xyz");
                        call.setPassword("zyx");
                        ret = (String) call.invoke(new Object[] {});
                        break;
         //System.out.println(ret);
         File f = new File("C:\\AnyName"+i+".xml");
         if (f.exists() && f.canWrite()) {
              f.delete();
         try {
              FileWriter write = new FileWriter("C:\\Anyname"+i+".xml",true);
              write.write(ret);
              write.close();
         } catch(IOException e) {
              e.printStackTrace();
         try {
              XMLReader reader = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
              InputSource in = null;
              try {
                   in = new InputSource(new FileInputStream(f));
              } catch(FileNotFoundException e) {
                   System.out.println("Datei nicht gefunden oder Zugriff verweigert: "+f.toString());
              Parser parser = new Parser();
              ContentHandler xmlImp = parser;
              reader.setContentHandler(xmlImp);
              reader.parse(in);
         } catch(Exception e) {
              System.out.println("Fehler: ");
              e.printStackTrace();
    }Can anybody please give me a hint? (or a link to a very good tutorial which
    is understandable for a beginner like me)
    Thanks in advance.

    When I execute the class I get the following message:
    Case 0
    AxisFault
    faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
    faultSubcode:
    faultString: java.net.UnknownHostException: ollilap.hsh-berlin.com
    faultActor:
    faultNode:
    faultDetail:
         {http://xml.apache.org/axis/}stackTrace:java.net.UnknownHostException: ollilap.hsh-berlin.com
         at java.net.PlainSocketImpl.connect(Unknown Source)
         at java.net.Socket.connect(Unknown Source)
         at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(Unknown Source)
         at com.sun.net.ssl.internal.ssl.SSLSocketImpl.<init>(Unknown Source)
         at com.sun.net.ssl.internal.ssl.SSLSocketFactoryImpl.createSocket(Unknown Source)
         at org.apache.axis.components.net.JSSESocketFactory.create(JSSESocketFactory.java:92)
         at org.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:181)
         at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.java:397)
         at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:135)
         at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
         at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
         at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
         at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
         at org.apache.axis.client.Call.invokeEngine(Call.java:2754)
         at org.apache.axis.client.Call.invoke(Call.java:2737)
         at org.apache.axis.client.Call.invoke(Call.java:2413)
         at org.apache.axis.client.Call.invoke(Call.java:2336)
         at org.apache.axis.client.Call.invoke(Call.java:1793)
         at Test.Test.runIt(Test.java:69)
         at Test.Test.main(Test.java:39)
         {http://xml.apache.org/axis/}hostname:Dell1
    java.net.UnknownHostException: ollilap.hsh-berlin.com
         at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
         at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:144)
         at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
         at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
         at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
         at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
         at org.apache.axis.client.Call.invokeEngine(Call.java:2754)
         at org.apache.axis.client.Call.invoke(Call.java:2737)
         at org.apache.axis.client.Call.invoke(Call.java:2413)
         at org.apache.axis.client.Call.invoke(Call.java:2336)
         at org.apache.axis.client.Call.invoke(Call.java:1793)
         at Test.Test.runIt(Test.java:69)
         at Test.Test.main(Test.java:39)
    Caused by: java.net.UnknownHostException: ollilap.hsh-berlin.com
         at java.net.PlainSocketImpl.connect(Unknown Source)
         at java.net.Socket.connect(Unknown Source)
         at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(Unknown Source)
         at com.sun.net.ssl.internal.ssl.SSLSocketImpl.<init>(Unknown Source)
         at com.sun.net.ssl.internal.ssl.SSLSocketFactoryImpl.createSocket(Unknown Source)
         at org.apache.axis.components.net.JSSESocketFactory.create(JSSESocketFactory.java:92)
         at org.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:181)
         at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.java:397)
         at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:135)
         ... 11 moreI execute it out of Eclipse. I think that that must be wrong (?).
    I created a *.war-file and tried to deploy it with Java Web Sevices Developer Pack
    DeployTool. But that doesn't work.

  • Character set conversion UTF-8 -- ISO-8859-1 generates question mark (?)

    I'm trying to convert an XML-file in UTF-8 format to another file with character set ISO-8859-1.
    My problem is that the ISO-8859-1 file generates a question mark (?) and puts it as a prefix in the file.
    ?<?xml version="1.0" encoding="UTF-8"?>
    <ns0:messagetype xmlns:ns0="urn:olof">
    <underkat>testv���rde</underkat>
    </ns0:messagetype>
    Is there a way to do the conversion without getting the question mark?
    My code looks as follows:
    public class ConvertEncoding {
         public static void main(String[] args) {
              String from = "UTF-8", to = "ISO-8859-1";
              String infile = "C:\\temp\\infile.xml", outfile = "C:\\temp\\outfile.xml";
              try {
                   convert(infile, outfile, from, to);
              } catch (Exception e) {
                   System.out.println(e.getMessage());
                   System.exit(1);
         private static void convert(String infile, String outfile,
                                            String from, String to)
                             throws IOException, UnsupportedEncodingException
              //Set up byte streams
              InputStream in = null;
              OutputStream out = null;
              if(infile != null) {
                   in = new FileInputStream(infile);
              if(outfile != null) {
                   out = new FileOutputStream(outfile);
              //Set up character streams
              Reader r = new BufferedReader(new InputStreamReader(in, from));
              Writer w = new BufferedWriter(new OutputStreamWriter(out, to));
              /*Copy characters from input to output.
               * The InputSreamreader converts
               * from Unicode to the output encoding.
               * Characters that cannot be represented in
               * the output encoding are output as '?'
              char[] buffer = new char[4096];
              int len;
              while((len = r.read(buffer))!= -1) { //Read a block of output
                   w.write(buffer, 0, len);
              r.close();
              w.flush();
              w.close();
    }

    Yes the next character is the '<'
    The file that I read from is generated by an integration platform. I send a plain file to it (supposedly in UTF-8 encoding) and it returns another file (in between I call my java class that converts the characterset from UTF-8 to ISO-8859-1). The file that I get back contains the '���' if the conversion doesn't work and '?' if the conversion worked.
    My solution so far is to skip the first "junk-characters" when reading from the inputstream. Something like:
    private static final char UTF_BOM = '\uFEFF'; //UTF-BOM = ?
    String from = "UTF-8", to = "ISO-8859-1";
    if (from != null && from.toLowerCase().startsWith("utf-")) { //Are we reading an UTF encoded file?
    /*Read first character of the UTF-Encoded file
    It will return '?' in the first position if we are dealing with UTF encoding If ? is returned we skip this character in the read
    try {
    r.mark(1); //Only allow to read one char for the reset function to work
    char c;
    int i = r.read();
    c = (char) i;
    if (String.valueOf(UTF_BOM).equalsIgnoreCase(String.valueOf(c))) {
    r.reset(); //reset to start position
    r.skip(1); //Skip first character when reading from the stream
    else {
    r.reset();
    } catch (IOException e) {
    e.getMessage();
    //return null;
    }

  • Import: performance question

    Hi, what is the different between these statements for application in term of performance?
    import java.io.*;
    and
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    Which one is faster for execution?

    Neither. Search the forums or web for the countless answers to the same question.

  • Questions regarding Disk I/O

    Hey there, I have some questions regarding disk i/o and I'm fairly new to Java.
    I've got an organized 500MB file and a table like structure (represented by an array) that tells me sections (bytes) within the file. With this I'm currently retrieving blocks of data using the following approach:
    // Assume id is just some arbitary int that represents an identifier.
    String f = "/scratch/torum/collection.jdx";
    int startByte = bytemap[id-1];
    int endByte = bytemap[id];
    try {
              FileInputStream stream = new FileInputStream(f);
              DataInputStream in = new DataInputStream(stream);
                    in.skipBytes(startByte);
              int position = collectionSize - in.available();
              // Keep looping until the end of the block.
              while(position <= endByte) {
                  line  = in.readLine();
                  // some pocessing here
                  String[]entry = line.split(" ");
                  String docid = entry[1];
                  int tf = Integer.parseInt(entry[2]);
                  // update the current position within the file.
                  position = collectionSize - in.available();
       } catch(IOException e) {
              e.printStackTrace();
       }This code does EXACTLY what I want it to do but with one complication. It isn't fast enough. I see that using BufferedReader is the choice after reading:
    http://java.sun.com/developer/technicalArticles/Programming/PerfTuning/
    I would love to use this Class but BufferedReader doesn't have the function, "skipBytes(), which is vital to achieve what I'm trying to do. I'm also aware that I shouldn't really be using the readLine() function of the DataInputStream Class.
    So could anyone suggest improvements to this code?
    Thanks
    null

    Okay I've got some results and turns out DataInputStream is faster...
    EDIT: I was wrong. RandomAccessFile becomes a bit faster according to my test code when the block size to read is large.
    So I guess I could write two routines in my program, RAF for when the block size is larger than an arbitary value and FileInputStream for small blocks.
    Here is the code:
    public void useRandomAccess() {
         String line = "";
         long start = 1385592, end = 1489808;
         try {
             RandomAccessFile in = new RandomAccessFile(f, "r");
             in.seek(start);
             while(start <= end) {     
              line = in.readLine();     
              String[]entry = line.split(" ");
              String docid = entry[1];
              int tf = Integer.parseInt(entry[2]);
              start = in.getFilePointer();
         } catch(FileNotFoundException e) {
             e.printStackTrace();
         } catch(IOException ioe) {
             ioe.printStackTrace();
    public void inputStream() {
         String line = "";
         int startByte = 1385592, endByte = 1489808;
         try {
             FileInputStream stream = new FileInputStream(f);
             DataInputStream in = new DataInputStream(stream);
             in.skipBytes(startByte);
             int position = collectionSize - in.available();
             while(position <= endByte) {
              line  = in.readLine();
              String[]entry = line.split(" ");
              String docid = entry[1];
              int tf = Integer.parseInt(entry[2]);
              position = collectionSize - in.available();
         } catch(IOException e) {
             e.printStackTrace();
        }and the main looks like this:
       public static void main(String[]args) {
         DiskTest dt = new DiskTest();
         long start = 0;
         long end = 0;
         start = System.currentTimeMillis();
         dt.useRandomAccess();
         end = System.currentTimeMillis();
         System.out.println("Random: "+(end-start)+"ms");
         start = System.currentTimeMillis();
         dt.inputStream();
         end = System.currentTimeMillis();
         System.out.println("Stream: "+(end-start)+"ms");
        }The result:
    Random: 345ms
    Stream: 235ms
    Hmmm not the kind of result I was hoping for... or is it something I've done wrong?

  • PKCS12 question

    I have one PKCS12 store .
    When I use this store with Server(server authendication) it works fine.
    When I use the same PKCS12 store on the client side it doesnt work.
    The client is not returning the certificate to server, and the server throws
    javax.net.ssl.SSLHandshakeException: null cert chain IOException occurred when processing request.
    Any idea why this is happening??
    I have another PKCS12 store which works fine with both server and client.
    What is the problem with my 1st PKCS12 store??
    Below is my server and client code and ssl trace
    ---------Client----------
    KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
    KeyStore keystore = KeyStore.getInstance("PKCS12");
    keystore.load(new FileInputStream(KEYSTORE), KEYSTOREPW);
    kmf.init(keystore, KEYPW);
    TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
    KeyStore truststore = KeyStore.getInstance("jks");
    truststore.load(new FileInputStream(TRUSTSTORE), TRUSTSTOREPW);
    tmf.init(truststore);
    SSLContext sslc = SSLContext.getInstance("SSLv3");
    sslc.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
    SSLSocketFactory factory = sslc.getSocketFactory();
    SSLSocket socket = (SSLSocket)factory.createSocket("babu", 443);
    -----Server---------
    Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
              System.setProperty("javax.net.debug", "all");
              KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
         KeyStore keystore = KeyStore.getInstance("PKCS12");
         keystore.load(new FileInputStream(KEYSTORE), KEYSTOREPW);
         kmf.init(keystore, KEYPW);
         TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
         KeyStore truststore = KeyStore.getInstance("jks");
         truststore.load(new FileInputStream(TRUSTSTORE), TRUSTSTOREPW);
         tmf.init(truststore);
         SSLContext sslc = SSLContext.getInstance("SSLv3");
         sslc.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
         ServerSocketFactory ssf = sslc.getServerSocketFactory();
         SSLServerSocket serverSocket =(SSLServerSocket) ssf.createServerSocket(serverPort);
         serverSocket.setNeedClientAuth(requireClientAuthentication);
    -------------SSL Server trace--------
    SecureServer version 1.0
    found key for : 1b171437ea2e3946aa536179d508b6eb_f9948e6e-6fdb-4f6e-b09e-613f60f00e41
    chain [0] = [
    Version: V3
    Subject: CN=babu babu, [email protected], DNQ=12141726907, L=dubai, C=AE
    Signature Algorithm: SHA1withRSA, OID = 1.2.840.113549.1.1.5
    Key: Sun RSA public key, 512 bits
    modulus: 9683790188147953162795730790793527257397758989267819282372960853921863644980017792669595318858981940986671279705015616513809624780681913479305781592431811
    public exponent: 65537
    Validity: [From: Wed Nov 01 12:09:39 GST 2006,
                   To: Fri Dec 01 12:09:38 GST 2006]
    Issuer: CN=Comtrust Demo CA, OU=Comtrust eBusiness Services, O=Etisalat, C=AE
    SerialNumber: [    0118]
    Certificate Extensions: 4
    [1]: ObjectId: 2.5.29.35 Criticality=false
    AuthorityKeyIdentifier [
    KeyIdentifier [
    0000: 7B 36 C0 C7 73 46 9E FB 0B C4 9E 93 48 B3 CA A5 .6..sF......H...
    0010: 07 1A FD B5 ....
    [2]: ObjectId: 2.5.29.17 Criticality=false
    SubjectAlternativeName [
    [RFC822Name: [email protected]]]
    [3]: ObjectId: 2.5.29.15 Criticality=false
    KeyUsage [
    DigitalSignature
    Key_Encipherment
    [4]: ObjectId: 2.5.29.19 Criticality=false
    BasicConstraints:[
    CA:false
    PathLen: undefined
    Unparseable certificate extensions: 1
    [1]: ObjectId: 2.5.29.31 Criticality=false
    0000: 30 66 30 64 A0 62 A0 60 86 5E 6C 64 61 70 3A 2F 0f0d.b.`.^ldap:/
    0010: 2F 6C 64 61 70 2E 63 6F 6D 74 72 75 73 74 2E 63 /ldap.comtrust.c
    0020: 6F 2E 61 65 2F 43 4E 3D 43 6F 6D 74 72 75 73 74 o.ae/CN=Comtrust
    0030: 20 44 65 6D 6F 20 43 41 2C 20 4F 55 3D 43 6F 6D Demo CA, OU=Com
    0040: 74 72 75 73 74 20 65 42 75 73 69 6E 65 73 73 20 trust eBusiness
    0050: 53 65 72 76 69 63 65 73 2C 4F 3D 45 74 69 73 61 Services,O=Etisa
    0060: 6C 61 74 2C 43 3D 41 45 lat,C=AE
    Algorithm: [SHA1withRSA]
    Signature:
    0000: 41 AC BF FB 89 E2 5D C3 41 40 95 74 41 9B D4 4D A.....][email protected]
    0010: 02 2D AE 92 85 CD 8B 55 5E 8A E9 CA 1F 20 36 2A .-.....U^.... 6*
    0020: 36 89 8F 84 22 AB 4F 8B B3 8B 7A DD 88 B3 98 B1 6...".O...z.....
    0030: EE D0 82 06 D2 75 2F DD 36 2E 30 C6 6D 92 0A 7D .....u/.6.0.m...
    0040: 61 F1 90 71 00 FA 09 86 2E B7 76 00 EE 4B 85 90 a..q......v..K..
    0050: CD A0 0A 20 F2 C7 0C 49 E4 A0 71 83 FB 9A 4A EF ... ...I..q...J.
    0060: ED 4A E9 36 C5 00 59 A8 EF 28 66 1E CC 81 FC FA .J.6..Y..(f.....
    0070: 75 B0 B5 B8 0E 5F BE 4E C6 D0 B3 BA 4E 4C 2C B9 u...._.N....NL,.
    adding as trusted cert:
    Subject: CN=babu babu, [email protected], DNQ=12141726907, L=dubai, C=AE
    Issuer: CN=Comtrust Demo CA, OU=Comtrust eBusiness Services, O=Etisalat, C=AE
    Algorithm: RSA; Serial number: 0x118
    Valid from Wed Nov 01 12:09:39 GST 2006 until Fri Dec 01 12:09:38 GST 2006
    trigger seeding of SecureRandom
    done seeding SecureRandom
    SecureServer is listening on port 443.
    matching alias: 1b171437ea2e3946aa536179d508b6eb_f9948e6e-6fdb-4f6e-b09e-613f60f00e41
    Accepted connection to 192.168.254.1 (192.168.254.1) on port 2879.
    ----------1-1-1-----
    [Raw read]: length = 5
    0000: 80 62 01 03 01 .b...
    [Raw read]: length = 95
    0000: 00 39 00 00 00 20 00 00 04 01 00 80 00 00 05 00 .9... ..........
    0010: 00 2F 00 00 33 00 00 32 00 00 0A 07 00 C0 00 00 ./..3..2........
    0020: 16 00 00 13 00 00 09 06 00 40 00 00 15 00 00 12 .........@......
    0030: 00 00 03 02 00 80 00 00 08 00 00 14 00 00 11 45 ...............E
    0040: 49 02 A0 AA 35 C2 92 48 CA FD 03 76 64 95 65 D6 I...5..H...vd.e.
    0050: 97 8F 8C 88 86 FD 03 19 0E 10 B8 7E 68 8F 30 ............h.0
    [read] MD5 and SHA1 hashes: len = 3
    0000: 01 03 01 ...
    [read] MD5 and SHA1 hashes: len = 95
    0000: 00 39 00 00 00 20 00 00 04 01 00 80 00 00 05 00 .9... ..........
    0010: 00 2F 00 00 33 00 00 32 00 00 0A 07 00 C0 00 00 ./..3..2........
    0020: 16 00 00 13 00 00 09 06 00 40 00 00 15 00 00 12 .........@......
    0030: 00 00 03 02 00 80 00 00 08 00 00 14 00 00 11 45 ...............E
    0040: 49 02 A0 AA 35 C2 92 48 CA FD 03 76 64 95 65 D6 I...5..H...vd.e.
    0050: 97 8F 8C 88 86 FD 03 19 0E 10 B8 7E 68 8F 30 ............h.0
    Thread-0, READ: SSL v2, contentType = Handshake, translated length = 73
    *** ClientHello, TLSv1
    RandomCookie: GMT: 1162412448 bytes = { 170, 53, 194, 146, 72, 202, 253, 3, 118, 100, 149, 101, 214, 151, 143, 140, 136, 134, 253, 3, 25, 14, 16, 184, 126, 104, 143, 48 }
    Session ID: {}
    Cipher Suites: [SSL_RSA_WITH_RC4_128_MD5, SSL_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, SSL_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_DES_CBC_SHA, SSL_DHE_RSA_WITH_DES_CBC_SHA, SSL_DHE_DSS_WITH_DES_CBC_SHA, SSL_RSA_EXPORT_WITH_RC4_40_MD5, SSL_RSA_EXPORT_WITH_DES40_CBC_SHA, SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA, SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA]
    Compression Methods: { 0 }
    %% Created: [Session-1, SSL_RSA_WITH_RC4_128_MD5]
    *** ServerHello, TLSv1
    RandomCookie: GMT: 1162412463 bytes = { 44, 156, 132, 21, 120, 87, 69, 229, 176, 58, 159, 137, 35, 145, 220, 129, 236, 8, 45, 127, 240, 221, 7, 210, 241, 52, 150, 138 }
    Session ID: {69, 73, 2, 175, 117, 130, 69, 187, 79, 198, 111, 18, 143, 44, 89, 188, 221, 232, 110, 109, 149, 122, 194, 49, 150, 66, 164, 65, 72, 177, 218, 89}
    Cipher Suite: SSL_RSA_WITH_RC4_128_MD5
    Compression Method: 0
    Cipher suite: SSL_RSA_WITH_RC4_128_MD5
    *** Certificate chain
    chain [0] = [
    Version: V3
    Subject: CN=babu babu, [email protected], DNQ=12141726907, L=dubai, C=AE
    Signature Algorithm: SHA1withRSA, OID = 1.2.840.113549.1.1.5
    Key: Sun RSA public key, 512 bits
    modulus: 9683790188147953162795730790793527257397758989267819282372960853921863644980017792669595318858981940986671279705015616513809624780681913479305781592431811
    public exponent: 65537
    Validity: [From: Wed Nov 01 12:09:39 GST 2006,
                   To: Fri Dec 01 12:09:38 GST 2006]
    Issuer: CN=Comtrust Demo CA, OU=Comtrust eBusiness Services, O=Etisalat, C=AE
    SerialNumber: [    0118]
    Certificate Extensions: 4
    [1]: ObjectId: 2.5.29.35 Criticality=false
    AuthorityKeyIdentifier [
    KeyIdentifier [
    0000: 7B 36 C0 C7 73 46 9E FB 0B C4 9E 93 48 B3 CA A5 .6..sF......H...
    0010: 07 1A FD B5 ....
    [2]: ObjectId: 2.5.29.17 Criticality=false
    SubjectAlternativeName [
    [RFC822Name: [email protected]]]
    [3]: ObjectId: 2.5.29.15 Criticality=false
    KeyUsage [
    DigitalSignature
    Key_Encipherment
    [4]: ObjectId: 2.5.29.19 Criticality=false
    BasicConstraints:[
    CA:false
    PathLen: undefined
    Unparseable certificate extensions: 1
    [1]: ObjectId: 2.5.29.31 Criticality=false
    0000: 30 66 30 64 A0 62 A0 60 86 5E 6C 64 61 70 3A 2F 0f0d.b.`.^ldap:/
    0010: 2F 6C 64 61 70 2E 63 6F 6D 74 72 75 73 74 2E 63 /ldap.comtrust.c
    0020: 6F 2E 61 65 2F 43 4E 3D 43 6F 6D 74 72 75 73 74 o.ae/CN=Comtrust
    0030: 20 44 65 6D 6F 20 43 41 2C 20 4F 55 3D 43 6F 6D Demo CA, OU=Com
    0040: 74 72 75 73 74 20 65 42 75 73 69 6E 65 73 73 20 trust eBusiness
    0050: 53 65 72 76 69 63 65 73 2C 4F 3D 45 74 69 73 61 Services,O=Etisa
    0060: 6C 61 74 2C 43 3D 41 45 lat,C=AE
    Algorithm: [SHA1withRSA]
    Signature:
    0000: 41 AC BF FB 89 E2 5D C3 41 40 95 74 41 9B D4 4D A.....][email protected]
    0010: 02 2D AE 92 85 CD 8B 55 5E 8A E9 CA 1F 20 36 2A .-.....U^.... 6*
    0020: 36 89 8F 84 22 AB 4F 8B B3 8B 7A DD 88 B3 98 B1 6...".O...z.....
    0030: EE D0 82 06 D2 75 2F DD 36 2E 30 C6 6D 92 0A 7D .....u/.6.0.m...
    0040: 61 F1 90 71 00 FA 09 86 2E B7 76 00 EE 4B 85 90 a..q......v..K..
    0050: CD A0 0A 20 F2 C7 0C 49 E4 A0 71 83 FB 9A 4A EF ... ...I..q...J.
    0060: ED 4A E9 36 C5 00 59 A8 EF 28 66 1E CC 81 FC FA .J.6..Y..(f.....
    0070: 75 B0 B5 B8 0E 5F BE 4E C6 D0 B3 BA 4E 4C 2C B9 u...._.N....NL,.
    *** CertificateRequest
    Cert Types: RSA, DSS,
    Cert Authorities:
    <CN=babu babu, [email protected], DNQ=12141726907, L=dubai, C=AE>
    *** ServerHelloDone
    [write] MD5 and SHA1 hashes: len = 938
    0000: 02 00 00 46 03 01 45 49 02 AF 2C 9C 84 15 78 57 ...F..EI..,...xW
    0010: 45 E5 B0 3A 9F 89 23 91 DC 81 EC 08 2D 7F F0 DD E..:..#.....-...
    0020: 07 D2 F1 34 96 8A 20 45 49 02 AF 75 82 45 BB 4F ...4.. EI..u.E.O
    0030: C6 6F 12 8F 2C 59 BC DD E8 6E 6D 95 7A C2 31 96 .o..,Y...nm.z.1.
    0040: 42 A4 41 48 B1 DA 59 00 04 00 0B 00 02 DD 00 02 B.AH..Y.........
    0050: DA 00 02 D7 30 82 02 D3 30 82 02 3C A0 03 02 01 ....0...0..<....
    0060: 02 02 02 01 18 30 0D 06 09 2A 86 48 86 F7 0D 01 .....0...*.H....
    0070: 01 05 05 00 30 61 31 0B 30 09 06 03 55 04 06 13 ....0a1.0...U...
    0080: 02 41 45 31 11 30 0F 06 03 55 04 0A 13 08 45 74 .AE1.0...U....Et
    0090: 69 73 61 6C 61 74 31 24 30 22 06 03 55 04 0B 13 isalat1$0"..U...
    00A0: 1B 43 6F 6D 74 72 75 73 74 20 65 42 75 73 69 6E .Comtrust eBusin
    00B0: 65 73 73 20 53 65 72 76 69 63 65 73 31 19 30 17 ess Services1.0.
    00C0: 06 03 55 04 03 13 10 43 6F 6D 74 72 75 73 74 20 ..U....Comtrust
    00D0: 44 65 6D 6F 20 43 41 30 1E 17 0D 30 36 31 31 30 Demo CA0...06110
    00E0: 31 30 38 30 39 33 39 5A 17 0D 30 36 31 32 30 31 1080939Z..061201
    00F0: 30 38 30 39 33 38 5A 30 6E 31 0B 30 09 06 03 55 080938Z0n1.0...U
    0100: 04 06 13 02 41 45 31 0E 30 0C 06 03 55 04 07 13 ....AE1.0...U...
    0110: 05 64 75 62 61 69 31 14 30 12 06 03 55 04 2E 13 .dubai1.0...U...
    0120: 0B 31 32 31 34 31 37 32 36 39 30 37 31 25 30 23 .121417269071%0#
    0130: 06 09 2A 86 48 86 F7 0D 01 09 01 16 16 62 61 62 ..*.H........bab
    0140: 75 65 40 65 6D 69 72 61 74 65 73 62 61 6E 6B 2E ue@nbdbank.
    0150: 63 6F 6D 31 12 30 10 06 03 55 04 03 13 09 62 61 com1.0...U....ba
    0160: 62 75 20 62 61 62 75 30 5C 30 0D 06 09 2A 86 48 bu babu0\0...*.H
    0170: 86 F7 0D 01 01 01 05 00 03 4B 00 30 48 02 41 00 .........K.0H.A.
    0180: B8 E5 61 65 47 4F AE 19 55 98 CE 56 A9 4F 73 33 ..aeGO..U..V.Os3
    0190: 5E 73 FD 26 1B AD 63 C8 C9 91 53 7E 7E CB 15 18 ^s.&..c...S.....
    01A0: EB 78 00 8A 23 DD 03 68 2E 1F AE 3D 5F 53 3D 64 .x..#..h...=_S=d
    01B0: 76 2C 87 F5 12 07 F3 17 C6 7D 04 F1 21 DF 9C C3 v,..........!...
    01C0: 02 03 01 00 01 A3 81 D0 30 81 CD 30 1F 06 03 55 ........0..0...U
    01D0: 1D 23 04 18 30 16 80 14 7B 36 C0 C7 73 46 9E FB .#..0....6..sF..
    01E0: 0B C4 9E 93 48 B3 CA A5 07 1A FD B5 30 09 06 03 ....H.......0...
    01F0: 55 1D 13 04 02 30 00 30 0B 06 03 55 1D 0F 04 04 U....0.0...U....
    0200: 03 02 05 A0 30 21 06 03 55 1D 11 04 1A 30 18 81 ....0!..U....0..
    0210: 16 62 61 62 75 65 40 65 6D 69 72 61 74 65 73 62 .babue@nbdb
    0220: 61 6E 6B 2E 63 6F 6D 30 6F 06 03 55 1D 1F 04 68 ank.com0o..U...h
    0230: 30 66 30 64 A0 62 A0 60 86 5E 6C 64 61 70 3A 2F 0f0d.b.`.^ldap:/
    0240: 2F 6C 64 61 70 2E 63 6F 6D 74 72 75 73 74 2E 63 /ldap.comtrust.c
    0250: 6F 2E 61 65 2F 43 4E 3D 43 6F 6D 74 72 75 73 74 o.ae/CN=Comtrust
    0260: 20 44 65 6D 6F 20 43 41 2C 20 4F 55 3D 43 6F 6D Demo CA, OU=Com
    0270: 74 72 75 73 74 20 65 42 75 73 69 6E 65 73 73 20 trust eBusiness
    0280: 53 65 72 76 69 63 65 73 2C 4F 3D 45 74 69 73 61 Services,O=Etisa
    0290: 6C 61 74 2C 43 3D 41 45 30 0D 06 09 2A 86 48 86 lat,C=AE0...*.H.
    02A0: F7 0D 01 01 05 05 00 03 81 81 00 41 AC BF FB 89 ...........A....
    02B0: E2 5D C3 41 40 95 74 41 9B D4 4D 02 2D AE 92 85 .][email protected]...
    02C0: CD 8B 55 5E 8A E9 CA 1F 20 36 2A 36 89 8F 84 22 ..U^.... 6*6..."
    02D0: AB 4F 8B B3 8B 7A DD 88 B3 98 B1 EE D0 82 06 D2 .O...z..........
    02E0: 75 2F DD 36 2E 30 C6 6D 92 0A 7D 61 F1 90 71 00 u/.6.0.m...a..q.
    02F0: FA 09 86 2E B7 76 00 EE 4B 85 90 CD A0 0A 20 F2 .....v..K..... .
    0300: C7 0C 49 E4 A0 71 83 FB 9A 4A EF ED 4A E9 36 C5 ..I..q...J..J.6.
    0310: 00 59 A8 EF 28 66 1E CC 81 FC FA 75 B0 B5 B8 0E .Y..(f.....u....
    0320: 5F BE 4E C6 D0 B3 BA 4E 4C 2C B9 0D 00 00 77 02 _.N....NL,....w.
    0330: 01 02 00 72 00 70 30 6E 31 0B 30 09 06 03 55 04 ...r.p0n1.0...U.
    0340: 06 13 02 41 45 31 0E 30 0C 06 03 55 04 07 13 05 ...AE1.0...U....
    0350: 64 75 62 61 69 31 14 30 12 06 03 55 04 2E 13 0B dubai1.0...U....
    0360: 31 32 31 34 31 37 32 36 39 30 37 31 25 30 23 06 121417269071%0#.
    0370: 09 2A 86 48 86 F7 0D 01 09 01 16 16 62 61 62 75 .*.H........babu
    0380: 65 40 65 6D 69 72 61 74 65 73 62 61 6E 6B 2E 63 [email protected]
    0390: 6F 6D 31 12 30 10 06 03 55 04 03 13 09 62 61 62 om1.0...U....bab
    03A0: 75 20 62 61 62 75 0E 00 00 00 u babu....
    Thread-0, WRITE: TLSv1 Handshake, length = 938
    [Raw write]: length = 943
    0000: 16 03 01 03 AA 02 00 00 46 03 01 45 49 02 AF 2C ........F..EI..,
    0010: 9C 84 15 78 57 45 E5 B0 3A 9F 89 23 91 DC 81 EC ...xWE..:..#....
    0020: 08 2D 7F F0 DD 07 D2 F1 34 96 8A 20 45 49 02 AF .-......4.. EI..
    0030: 75 82 45 BB 4F C6 6F 12 8F 2C 59 BC DD E8 6E 6D u.E.O.o..,Y...nm
    0040: 95 7A C2 31 96 42 A4 41 48 B1 DA 59 00 04 00 0B .z.1.B.AH..Y....
    0050: 00 02 DD 00 02 DA 00 02 D7 30 82 02 D3 30 82 02 .........0...0..
    0060: 3C A0 03 02 01 02 02 02 01 18 30 0D 06 09 2A 86 <.........0...*.
    0070: 48 86 F7 0D 01 01 05 05 00 30 61 31 0B 30 09 06 H........0a1.0..
    0080: 03 55 04 06 13 02 41 45 31 11 30 0F 06 03 55 04 .U....AE1.0...U.
    0090: 0A 13 08 45 74 69 73 61 6C 61 74 31 24 30 22 06 ...Etisalat1$0".
    00A0: 03 55 04 0B 13 1B 43 6F 6D 74 72 75 73 74 20 65 .U....Comtrust e
    00B0: 42 75 73 69 6E 65 73 73 20 53 65 72 76 69 63 65 Business Service
    00C0: 73 31 19 30 17 06 03 55 04 03 13 10 43 6F 6D 74 s1.0...U....Comt
    00D0: 72 75 73 74 20 44 65 6D 6F 20 43 41 30 1E 17 0D rust Demo CA0...
    00E0: 30 36 31 31 30 31 30 38 30 39 33 39 5A 17 0D 30 061101080939Z..0
    00F0: 36 31 32 30 31 30 38 30 39 33 38 5A 30 6E 31 0B 61201080938Z0n1.
    0100: 30 09 06 03 55 04 06 13 02 41 45 31 0E 30 0C 06 0...U....AE1.0..
    0110: 03 55 04 07 13 05 64 75 62 61 69 31 14 30 12 06 .U....dubai1.0..
    0120: 03 55 04 2E 13 0B 31 32 31 34 31 37 32 36 39 30 .U....1214172690
    0130: 37 31 25 30 23 06 09 2A 86 48 86 F7 0D 01 09 01 71%0#..*.H......
    0140: 16 16 62 61 62 75 65 40 65 6D 69 72 61 74 65 73 ..babue@nbd
    0150: 62 61 6E 6B 2E 63 6F 6D 31 12 30 10 06 03 55 04 bank.com1.0...U.
    0160: 03 13 09 62 61 62 75 20 62 61 62 75 30 5C 30 0D ...babu babu0\0.
    0170: 06 09 2A 86 48 86 F7 0D 01 01 01 05 00 03 4B 00 ..*.H.........K.
    0180: 30 48 02 41 00 B8 E5 61 65 47 4F AE 19 55 98 CE 0H.A...aeGO..U..
    0190: 56 A9 4F 73 33 5E 73 FD 26 1B AD 63 C8 C9 91 53 V.Os3^s.&..c...S
    01A0: 7E 7E CB 15 18 EB 78 00 8A 23 DD 03 68 2E 1F AE ......x..#..h...
    01B0: 3D 5F 53 3D 64 76 2C 87 F5 12 07 F3 17 C6 7D 04 =_S=dv,.........
    01C0: F1 21 DF 9C C3 02 03 01 00 01 A3 81 D0 30 81 CD .!...........0..
    01D0: 30 1F 06 03 55 1D 23 04 18 30 16 80 14 7B 36 C0 0...U.#..0....6.
    01E0: C7 73 46 9E FB 0B C4 9E 93 48 B3 CA A5 07 1A FD .sF......H......
    01F0: B5 30 09 06 03 55 1D 13 04 02 30 00 30 0B 06 03 .0...U....0.0...
    0200: 55 1D 0F 04 04 03 02 05 A0 30 21 06 03 55 1D 11 U........0!..U..
    0210: 04 1A 30 18 81 16 62 61 62 75 65 40 65 6D 69 72 ..0...babue@emir
    0220: 61 74 65 73 62 61 6E 6B 2E 63 6F 6D 30 6F 06 03 atesbank.com0o..
    0230: 55 1D 1F 04 68 30 66 30 64 A0 62 A0 60 86 5E 6C U...h0f0d.b.`.^l
    0240: 64 61 70 3A 2F 2F 6C 64 61 70 2E 63 6F 6D 74 72 dap://ldap.comtr
    0250: 75 73 74 2E 63 6F 2E 61 65 2F 43 4E 3D 43 6F 6D ust.co.ae/CN=Com
    0260: 74 72 75 73 74 20 44 65 6D 6F 20 43 41 2C 20 4F trust Demo CA, O
    0270: 55 3D 43 6F 6D 74 72 75 73 74 20 65 42 75 73 69 U=Comtrust eBusi
    0280: 6E 65 73 73 20 53 65 72 76 69 63 65 73 2C 4F 3D ness Services,O=
    0290: 45 74 69 73 61 6C 61 74 2C 43 3D 41 45 30 0D 06 Etisalat,C=AE0..
    02A0: 09 2A 86 48 86 F7 0D 01 01 05 05 00 03 81 81 00 .*.H............
    02B0: 41 AC BF FB 89 E2 5D C3 41 40 95 74 41 9B D4 4D A.....][email protected]
    02C0: 02 2D AE 92 85 CD 8B 55 5E 8A E9 CA 1F 20 36 2A .-.....U^.... 6*
    02D0: 36 89 8F 84 22 AB 4F 8B B3 8B 7A DD 88 B3 98 B1 6...".O...z.....
    02E0: EE D0 82 06 D2 75 2F DD 36 2E 30 C6 6D 92 0A 7D .....u/.6.0.m...
    02F0: 61 F1 90 71 00 FA 09 86 2E B7 76 00 EE 4B 85 90 a..q......v..K..
    0300: CD A0 0A 20 F2 C7 0C 49 E4 A0 71 83 FB 9A 4A EF ... ...I..q...J.
    0310: ED 4A E9 36 C5 00 59 A8 EF 28 66 1E CC 81 FC FA .J.6..Y..(f.....
    0320: 75 B0 B5 B8 0E 5F BE 4E C6 D0 B3 BA 4E 4C 2C B9 u...._.N....NL,.
    0330: 0D 00 00 77 02 01 02 00 72 00 70 30 6E 31 0B 30 ...w....r.p0n1.0
    0340: 09 06 03 55 04 06 13 02 41 45 31 0E 30 0C 06 03 ...U....AE1.0...
    0350: 55 04 07 13 05 64 75 62 61 69 31 14 30 12 06 03 U....dubai1.0...
    0360: 55 04 2E 13 0B 31 32 31 34 31 37 32 36 39 30 37 U....12141726907
    0370: 31 25 30 23 06 09 2A 86 48 86 F7 0D 01 09 01 16 1%0#..*.H.......
    0380: 16 62 61 62 75 65 40 65 6D 69 72 61 74 65 73 62 .babue@nbdb
    0390: 61 6E 6B 2E 63 6F 6D 31 12 30 10 06 03 55 04 03 ank.com1.0...U..
    03A0: 13 09 62 61 62 75 20 62 61 62 75 0E 00 00 00 ..babu babu....
    [Raw read]: length = 5
    0000: 16 03 01 00 4D ....M
    [Raw read]: length = 77
    0000: 0B 00 00 03 00 00 00 10 00 00 42 00 40 25 49 2D ..........B.@%I-
    0010: 10 ED DE 8A 27 28 E1 F9 CD 1B 1C 51 E1 A0 C7 2E ....'(.....Q....
    0020: CA 7C A0 1F 19 E2 88 C4 41 49 33 7A CD 1C EA D8 ........AI3z....
    0030: 6A C9 EC 32 88 81 73 D1 42 A4 7D BE 17 32 E3 5B j..2..s.B....2.[
    0040: EA A5 2C 5D EC 0D 8A 76 CB F6 1D 82 0B ..,]...v.....
    Thread-0, READ: TLSv1 Handshake, length = 77
    *** Certificate chain
    Thread-0, SEND TLSv1 ALERT: fatal, description = bad_certificate
    Thread-0, WRITE: TLSv1 Alert, length = 2
    [Raw write]: length = 7
    0000: 15 03 01 00 02 02 2A ......*
    Thread-0, called closeSocket()
    Thread-0, handling exception: javax.net.ssl.SSLHandshakeException: null cert chain
    IOException occurred when processing request.
    Thread-0, called close()
    Thread-0, called closeInternal(true)
    Accepted connection to 192.168.254.1 (192.168.254.1) on port 2990.
    ----------1-1-1-----
    [Raw read]: length = 5
    0000: 80 62 01 03 01 .b...
    [Raw read]: length = 95
    0000: 00 39 00 00 00 20 00 00 04 01 00 80 00 00 05 00 .9... ..........
    0010: 00 2F 00 00 33 00 00 32 00 00 0A 07 00 C0 00 00 ./..3..2........
    0020: 16 00 00 13 00 00 09 06 00 40 00 00 15 00 00 12 .........@......
    0030: 00 00 03 02 00 80 00 00 08 00 00 14 00 00 11 45 ...............E
    0040: 49 06 56 DE 63 83 34 50 9F A8 B4 E3 30 2F C0 79 I.V.c.4P....0/.y
    0050: 42 45 1A 6A A3 A4 20 2D 89 10 A0 25 AE 48 66 BE.j.. -...%.Hf
    [read] MD5 and SHA1 hashes: len = 3
    0000: 01 03 01 ...
    [read] MD5 and SHA1 hashes: len = 95
    0000: 00 39 00 00 00 20 00 00 04 01 00 80 00 00 05 00 .9... ..........
    0010: 00 2F 00 00 33 00 00 32 00 00 0A 07 00 C0 00 00 ./..3..2........
    0020: 16 00 00 13 00 00 09 06 00 40 00 00 15 00 00 12 .........@......
    0030: 00 00 03 02 00 80 00 00 08 00 00 14 00 00 11 45 ...............E
    0040: 49 06 56 DE 63 83 34 50 9F A8 B4 E3 30 2F C0 79 I.V.c.4P....0/.y
    0050: 42 45 1A 6A A3 A4 20 2D 89 10 A0 25 AE 48 66 BE.j.. -...%.Hf
    Thread-1, READ: SSL v2, contentType = Handshake, translated length = 73
    *** ClientHello, TLSv1
    RandomCookie: GMT: 1162413654 bytes = { 222, 99, 131, 52, 80, 159, 168, 180, 227, 48, 47, 192, 121, 66, 69, 26, 106, 163, 164, 32, 45, 137, 16, 160, 37, 174, 72, 102 }
    Session ID: {}
    Cipher Suites: [SSL_RSA_WITH_RC4_128_MD5, SSL_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, SSL_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_DES_CBC_SHA, SSL_DHE_RSA_WITH_DES_CBC_SHA, SSL_DHE_DSS_WITH_DES_CBC_SHA, SSL_RSA_EXPORT_WITH_RC4_40_MD5, SSL_RSA_EXPORT_WITH_DES40_CBC_SHA, SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA, SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA]
    Compression Methods: { 0 }
    %% Created: [Session-2, SSL_RSA_WITH_RC4_128_MD5]
    *** ServerHello, TLSv1
    RandomCookie: GMT: 1162413669 bytes = { 30, 208, 109, 78, 140, 101, 21, 219, 26, 140, 158, 150, 32, 100, 190, 23, 140, 102, 8, 144, 137, 86, 160, 236, 214, 245, 33, 94 }
    Session ID: {69, 73, 6, 101, 151, 179, 48, 160, 233, 21, 49, 37, 62, 184, 27, 54, 134, 50, 218, 49, 149, 61, 139, 27, 93, 80, 81, 120, 238, 184, 24, 110}
    Cipher Suite: SSL_RSA_WITH_RC4_128_MD5
    Compression Method: 0
    Cipher suite: SSL_RSA_WITH_RC4_128_MD5
    *** Certificate chain
    chain [0] = [
    Version: V3
    Subject: CN=babu babu, [email protected], DNQ=12141726907, L=dubai, C=AE
    Signature Algorithm: SHA1withRSA, OID = 1.2.840.113549.1.1.5
    Key: Sun RSA public key, 512 bits
    modulus: 9683790188147953162795730790793527257397758989267819282372960853921863644980017792669595318858981940986671279705015616513809624780681913479305781592431811
    public exponent: 65537
    Validity: [From: Wed Nov 01 12:09:39 GST 2006,
                   To: Fri Dec 01 12:09:38 GST 2006]
    Issuer: CN=Comtrust Demo CA, OU=Comtrust eBusiness Services, O=Etisalat, C=AE
    SerialNumber: [    0118]
    Certificate Extensions: 4
    [1]: ObjectId: 2.5.29.35 Criticality=false
    AuthorityKeyIdentifier [
    KeyIdentifier [
    0000: 7B 36 C0 C7 73 46 9E FB 0B C4 9E 93 48 B3 CA A5 .6..sF......H...
    0010: 07 1A FD B5 ....
    [2]: ObjectId: 2.5.29.17 Criticality=false
    SubjectAlternativeName [
    [RFC822Name: [email protected]]]
    [3]: ObjectId: 2.5.29.15 Criticality=false
    KeyUsage [
    DigitalSignature
    Key_Encipherment
    [4]: ObjectId: 2.5.29.19 Criticality=false
    BasicConstraints:[
    CA:false
    PathLen: undefined
    Unparseable certificate extensions: 1
    [1]: ObjectId: 2.5.29.31 Criticality=false
    0000: 30 66 30 64 A0 62 A0 60 86 5E 6C 64 61 70 3A 2F 0f0d.b.`.^ldap:/
    0010: 2F 6C 64 61 70 2E 63 6F 6D 74 72 75 73 74 2E 63 /ldap.comtrust.c
    0020: 6F 2E 61 65 2F 43 4E 3D 43 6F 6D 74 72 75 73 74 o.ae/CN=Comtrust
    0030: 20 44 65 6D 6F 20 43 41 2C 20 4F 55 3D 43 6F 6D Demo CA, OU=Com
    0040: 74 72 75 73 74 20 65 42 75 73 69 6E 65 73 73 20 trust eBusiness
    0050: 53 65 72 76 69 63 65 73 2C 4F 3D 45 74 69 73 61 Services,O=Etisa
    0060: 6C 61 74 2C 43 3D 41 45 lat,C=AE
    Algorithm: [SHA1withRSA]
    Signature:
    0000: 41 AC BF FB 89 E2 5D C3 41 40 95 74 41 9B D4 4D A.....][email protected]
    0010: 02 2D AE 92 85 CD 8B 55 5E 8A E9 CA 1F 20 36 2A .-.....U^.... 6*
    0020: 36 89 8F 84 22 AB 4F 8B B3 8B 7A DD 88 B3 98 B1 6...".O...z.....
    0030: EE D0 82 06 D2 75 2F DD 36 2E 30 C6 6D 92 0A 7D .....u/.6.0.m...
    0040: 61 F1 90 71 00 FA 09 86 2E B7 76 00 EE 4B 85 90 a..q......v..K..
    0050: CD A0 0A 20 F2 C7 0C 49 E4 A0 71 83 FB 9A 4A EF ... ...I..q...J.
    0060: ED 4A E9 36 C5 00 59 A8 EF 28 66 1E CC 81 FC FA .J.6..Y..(f.....
    0070: 75 B0 B5 B8 0E 5F BE 4E C6 D0 B3 BA 4E 4C 2C B9 u...._.N....NL,.
    *** CertificateRequest
    Cert Types: RSA, DSS,
    Cert Authorities:
    <CN=babu babu, [email protected], DNQ=12141726907, L=dubai, C=AE>
    *** ServerHelloDone
    [write] MD5 and SHA1 hashes: len = 938
    0000: 02 00 00 46 03 01 45 49 06 65 1E D0 6D 4E 8C 65 ...F..EI.e..mN.e
    0010: 15 DB 1A 8C 9E 96 20 64 BE 17 8C 66 08 90 89 56 ...... d...f...V
    0020: A0 EC D6 F5 21 5E 20 45 49 06 65 97 B3 30 A0 E9 ....!^ EI.e..0..
    0030: 15 31 25 3E B8 1B 36 86 32 DA 31 95 3D 8B 1B 5D .1%>..6.2.1.=..]
    0040: 50 51 78 EE B8 18 6E 00 04 00 0B 00 02 DD 00 02 PQx...n.........
    0050: DA 00 02 D7 30 82 02 D3 30 82 02 3C A0 03 02 01 ....0...0..<....
    0060: 02 02 02 01 18 30 0D 06 09 2A 86 48 86 F7 0D 01 .....0...*.H....
    0070: 01 05 05 00 30 61 31 0B 30 09 06 03 55 04 06 13 ....0a1.0...U...
    0080: 02 41 45 31 11 30 0F 06 03 55 04 0A 13 08 45 74 .AE1.0...U....Et
    0090: 69 73 61 6C 61 74 31 24 30 22 06 03 55 04 0B 13 isalat1$0"..U...
    00A0: 1B 43 6F 6D 74 72 75 73 74 20 65 42 75 73 69 6E .Comtrust eBusin
    00B0: 65 73 73 20 53 65 72 76 69 63 65 73 31 19 30 17 ess Services1.0.
    00C0: 06 03 55 04 03 13 10 43 6F 6D 74 72 75 73 74 20 ..U....Comtrust
    00D0: 44 65 6D 6F 20 43 41 30 1E 17 0D 30 36 31 31 30 Demo CA0...06110
    00E0: 31 30 38 30 39 33 39 5A 17 0D 30 36 31 32 30 31 1080939Z..061201
    00F0: 30 38 30 39 33 38 5A 30 6E 31 0B 30 09 06 03 55 080938Z0n1.0...U
    0100: 04 06 13 02 41 45 31 0E 30 0C 06 03 55 04 07 13 ....AE1.0...U...
    0110: 05 64 75 62 61 69 31 14 30 12 06 03 55 04 2E 13 .dubai1.0...U...
    0120: 0B 31 32 31 34 31 37 32 36 39 30 37 31 25 30 23 .121417269071%0#
    0130: 06 09 2A 86 48 86 F7 0D 01 09 01 16 16 62 61 62 ..*.H........bab
    0140: 75 65 40 65 6D 69 72 61 74 65 73 62 61 6E 6B 2E ue@nbdbank.
    0150: 63 6F 6D 31 12 30 10 06 03 55 04 03 13 09 62 61 com1.0...U....ba
    0160: 62 75 20 62 61 62 75 30 5C 30 0D 06 09 2A 86 48 bu babu0\0...*.H
    0170: 86 F7 0D 01 01 01 05 00 03 4B 00 30 48 02 41 00 .........K.0H.A.
    0180: B8 E5 61 65 47 4F AE 19 55 98 CE 56 A9 4F 73 33 ..aeGO..U..V.Os3
    0190: 5E 73 FD 26 1B AD 63 C8 C9 91 53 7E 7E CB 15 18 ^s.&..c...S.....
    01A0: EB 78 00 8A 23 DD 03 68 2E 1F AE 3D 5F 53 3D 64 .x..#..h...=_S=d
    01B0: 76 2C 87 F5 12 07 F3 17 C6 7D 04 F1 21 DF 9C C3 v,..........!...
    01C0: 02 03 01 00 01 A3 81 D0 30 81 CD 30 1F 06 03 55 ........0..0...U
    01D0: 1D 23 04 18 30 16 80 14 7B 36 C0 C7 73 46 9E FB .#..0....6..sF..
    01E0: 0B C4 9E 93 48 B3 CA A5 07 1A FD B5 30 09 06 03 ....H.......0...
    01F0: 55 1D 13 04 02 30 00 30 0B 06 03 55 1D 0F 04 04 U....0.0...U....
    0200: 03 02 05 A0 30 21 06 03 55 1D 11 04 1A 30 18 81 ....0!..U....0..
    0210: 16 62 61 62 75 65 40 65 6D 69 72 61 74 65 73 62 .babue@nbdb
    0220: 61 6E 6B 2E 63 6F 6D 30 6F 06 03 55 1D 1F 04 68 ank.com0o..U...h
    0230: 30 66 30 64 A0 62 A0 60 86 5E 6C 64 61 70 3A 2F 0f0d.b.`.^ldap:/
    0240: 2F 6C 64 61 70 2E 63 6F 6D 74 72 75 73 74 2E 63 /ldap.comtrust.c
    0250: 6F 2E 61 65 2F 43 4E 3D 43 6F 6D 74 72 75 73 74 o.ae/CN=Comtrust
    0260: 20 44 65 6D 6F 20 43 41 2C 20 4F 55 3D 43 6F 6D Demo CA, OU=Com
    0270: 74 72 75 73 74 20 65 42 75 73 69 6E 65 73 73 20 trust eBusiness
    0280: 53 65 72 76 69 63 65 73 2C 4F 3D 45 74 69 73 61 Services,O=Etisa
    0290: 6C 61 74 2C 43 3D 41 45 30 0D 06 09 2A 86 48 86 lat,C=AE0...*.H.
    02A0: F7 0D 01 01 05 05 00 03 81 81 00 41 AC BF FB 89 ...........A....
    02B0: E2 5D C3 41 40 95 74 41 9B D4 4D 02 2D AE 92 85 .][email protected]...
    02C0: CD 8B 55 5E 8A E9 CA 1F 20 36 2A 36 89 8F 84 22 ..U^.... 6*6..."
    02D0: AB 4F 8B B3 8B 7A DD 88 B3 98 B1 EE D0 82 06 D2 .O...z..........
    02E0: 75 2F DD 36 2E 30 C6 6D 92 0A 7D 61 F1 90 71 00 u/.6.0.m...a..q.
    02F0: FA 09 86 2E B7 76 00 EE 4B 85 90 CD A0 0A 20 F2 .....v..K..... .
    0300: C7 0C 49 E4 A0 71 83 FB 9A 4A EF ED 4A E9 36 C5 ..I..q...J..J.6.
    0310: 00 59 A8 EF 28 66 1E CC 81 FC FA 75 B0 B5 B8 0E .Y..(f.....u....
    0320: 5F BE 4E C6 D0 B3 BA 4E 4C 2C B9 0D 00 00 77 02 _.N....NL,....w.
    0330: 01 02 00 72 00 70 30 6E 31 0B 30 09 06 03 55 04 ...r.p0n1.0...U.
    0340: 06 13 02 41 45 31 0E 30 0C 06 03 55 04 07 13 05 ...AE1.0...U....
    0350: 64 75 62 61 69 31 14 30 12 06 03 55 04 2E 13 0B dubai1.0...U....
    0360: 31 32 31 34 31 37 32 36 39 30 37 31 25 30 23 06 121417269071%0#.
    0370: 09 2A 86 48 86 F7 0D 01 09 01 16 16 62 61 62 75 .*.H........babu
    0380: 65 40 65 6D 69 72 61 74 65 73 62 61 6E 6B 2E 63 [email protected]
    0390: 6F 6D 31 12 30 10 06 03 55 04 03 13 09 62 61 62 om1.0...U....bab
    03A0: 75 20 62 61 62 75 0E 00 00 00 u babu....
    Thread-1, WRITE: TLSv1 Handshake, length = 938
    [Raw write]: length = 943
    0000: 16 03 01 03 AA 02 00 00 46 03 01 45 49 06 65 1E ........F..EI.e.
    0010: D0 6D 4E 8C 65 15 DB 1A 8C 9E 96 20 64 BE 17 8C .mN.e...... d...
    0020: 66 08 90 89 56 A0 EC D6 F5 21 5E 20 45 49 06 65 f...V....!^ EI.e
    0030: 97 B3 30 A0 E9 15 31 25 3E B8 1B 36 86 32 DA 31 ..0...1%>..6.2.1
    0040: 95 3D 8B 1B 5D 50 51 78

    Few questions for you, before I go off in a completely
    different direction than you're after...
    Are you using a third party Crypto Provider?
    Do you need to be able to read these files into Java
    often, or is this a one-time-only type conversion?Hi,
    I got these files from a third party as part of a small project. They used openssl to generate the private keys, and the corresponding certificates. They dont have a file such as keyfile or anything similar so that I could generate a keystore. But I know the passwords which was used to generate the key.
    The private keys are in pem (they've used pkcs12) and stored as:
    -----BEGIN RSA PRIVATE KEY-----
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    -----END RSA PRIVATE KEY-----
    I don't know how to read the private keys. I've managed to read the certificates by doing:
    FileInputStream in = new FileInputStream(filename);
    CertificateFactory cf = CertificateFactory.getInstance("X509");
    cert = (X509Certificate) cf.generateCertificate(in);
    in.close();
    I am using Bouncy Castle Crypto, and yes I will need to read these files often.
    Thanks

  • Some general questions about multi-threading

    Hey Everybody,
    I have a dilemma with a multi-threaded program that I have written.
    Well to be truthful I actually wrote the program with no consideration whatsoever for multithreading.
    As a result of this complete lack of concern I get a completely hung user interface.
    My program performs a lot of network communications over URL��s and also writes information from URL��s to disk. The combination of networking and I/O in my program and the fact that I have not built multi-threading into the program has lead to complete failure of the user interface. When I say complete failure I mean complete failure. If it were only button��s not responding then I wouldn��t be all that worried, however the entire drawing area of my programs ��Frame�� completely freezes. It��s cool if nothing is maximized or minimized over the frame but as soon as this happens my programs drawing area has a ��serious hang over!��.
    I have begun learning about threads, in principle they sound wicked however in practice they have proven to be a brain tease (oops �K.. honesty).
    The difficulty of threads should not be all that daunting to me, however I have a couple of very simple questions that I would love to have answered�K..anybody out there!!!!!!!!!
    This is the normal basic method of running a thread that I have been attempting to incorporate into my program:
    1). Extend the thread class,
    2). Override the run() method in the subclass (created from step 1),
    3). Create an instance of the subclass,
    4). Call the start() method on the instance (from step 3).
    I have read that every statement the thread will execute is contained within it��s run() method.
    Question 1). This being the case is it possible to have member variables or methods inside a class that extends thread? Please explain!
    Question 2). Can a class that extends thread contain a constructor? Please explain!
    Question 3). If a subclass of thread cannot contain a constructor as I assume to be the case then how can code executing within the newly spawned thread reference information from the object that spawned it?
    If anybody out there on the great net can answer even half of one of these questions I will be more than grateful. Thanks for your time, and rock on Java!
    David

    Thread t = new Thread(MyRunnableDerivedClass);
    t.start();I hope it is understood that MyRunnableDerivedClass is actually an object of the MyRunnableDerivedClass. sorry for the confusion.
    so here's a thread that reads from a file using constructors, member variables, other funcs. It's not optimal but shows use of all of the above. I just typed this in so there are probably syntax errors, but you should get the point.
    public class ThreadedFileReader implements Runnable
        private File m_File;
        byte[] contents = new byte[0];
        public ThreadedFileReader( File f )
           m_File = f;
        public void run()
            BufferedInputStream bis = null;
            try
                bis = new BufferedInputStream( new FileInputStream( m_File ));
                int avail = bis.available();
                while (avail > 0)
                    int oldLen = contents.length();
                    contents = expand( contents, avail );
                    bis.read( contents, oldLen, avail );
                    avail = bis.available();
            catch (Exception e)
            { //do something witty
            finally
                try{ if (bis != null) bis.close(); } catch (Exception e){}
       private byte[] expand( byte[] oldBuf, int addedLen )
          byte[] newBuf = new char[oldBuf.length + addedLen];
          System.arrayCopy( newBuf, 0, oldBuf, 0, oldBuf.length );
          return newBuf;
       public byte[] getContents()
           return contents;
    //here's where we use it
    File f = new File( "c:\myfile" );
    ThreadedFileReader tfr = new ThreadedFileReader( f );
    Thread t = new Thread( tfr );
    t.start();
    t.join();
    // At this point the thread has died, but the thread object still exists
    byte [] data = tfr.getContents();

  • Relatively simple question- I'm a bit new at this

    Hello folks
    I have a Hebrew text in a txt file that I need to transfer to another empty txt file. My question is how do I know which encoding this Hebrew is in? What must I use in order to properly work with Hebrew in my OutputStream and InputStream?
    Many thanks.
    Ilan

    Thanks noah, but I've already tried that. What I end up with is data that is not coded correctly in the result file. Here is what I've come up with so far: "list1" is the Hebrew list, while "list2" is in English, and needs no special encoding:
    import java.io.*;
    import java.util.*;
    public class combineLists
         public static void main(String[] args) throws IOException
         String newLine=System.getProperty("line.separator");
         StringBuffer buffer = new StringBuffer();
    try {
    FileInputStream fisH = new FileInputStream("list2.txt");
    FileReader fisE = new FileReader("list1.txt");
              BufferedReader buffEng= new BufferedReader(fisE);
              InputStreamReader isrH = new InputStreamReader(fisH, "ISO_8859-9");
    BufferedReader inH = new BufferedReader(isrH);
              FileOutputStream fos = new FileOutputStream("final.txt");
    Writer out = new OutputStreamWriter(fos,"ISO_8859-9");
    int ch;
    while ((ch = inH.read()) > -1 ) {
                   out.write(inH.readLine()+newLine+buffEng.readLine());
    inH.close();
              out.close();
    } catch (IOException e) {
    e.printStackTrace();
         // try {
    //FileOutputStream fos = new FileOutputStream("final.txt");
    // Writer out = new OutputStreamWriter(fos,"ISO_8859-9");
    // out.write(buffer.toString());
    // } catch (IOException e) {
    // e.printStackTrace();
    again, my results here are a list of part-English, part-garbage. See what you can make of it.
    Thanks
    Ilan

  • FileInputStream memory leak..?

    hi..hope anyone can help..
    this question is related to bouncycastle API, but i think my problem here is more related to the general java programming..
    i'm pretty confused here. It seems i can't decrypt my file using the statements below.
    =======================
    textLocation="D:/FYP/tempMessage.txt.asc";
    FileInputStream in = new FileInputStream(textLocation);
    FileInputStream keyIn = new FileInputStream("D:/FYP/[email protected]");
    passPhrase="cadbury";
    password = passPhrase.toCharArray(); //convert from string to char
    decryptFile(in,keyIn,password); //call the function decryptFile provided with the bouncycastle's openpgp KeyBasedFileProcessor source code. decrypt file receive the arguments InputStream,InputStream,and char[].
    ========================
    usually, after decrypting, the resulting plain text file will be called tempMessage.txt (the original ciphertext file name minus the .asc).
    but when i tried running my program, only the message "message integrity check passed" appeared, and nothing else will happen. I got no idea whether the file is successfully decrypted or not. If yes, where did the plaintext file is stored (or is it possible there's some kind of memory leak here) or if no, what should be done?
    any help are greatly appreciated.thanks a lot.

    here's the source code. it's the same as provided with bouncycastle openpgp's example:
    * decrypt the passed in message stream
    private static void decryptFile(
    InputStream in,
    InputStream keyIn,
    char[] passwd)
    throws Exception
    in = PGPUtil.getDecoderStream(in);
    try
    PGPObjectFactory pgpF = new PGPObjectFactory(in);
    PGPEncryptedDataList enc;
    Object o = pgpF.nextObject();
    // the first object might be a PGP marker packet.
    if (o instanceof PGPEncryptedDataList)
    enc = (PGPEncryptedDataList)o;
    else
    enc = (PGPEncryptedDataList)pgpF.nextObject();
    // find the secret key
    Iterator it = enc.getEncyptedDataObjects();
    PGPPrivateKey sKey = null;
    PGPPublicKeyEncryptedData pbe = null;
    while (sKey == null && it.hasNext())
    pbe = (PGPPublicKeyEncryptedData)it.next();
    sKey = findSecretKey(keyIn, pbe.getKeyID(), passwd);
    if (sKey == null)
    throw new IllegalArgumentException("secret key for message not found.");
    InputStream clear = pbe.getDataStream(sKey, "BC");
    PGPObjectFactory plainFact = new PGPObjectFactory(clear);
    PGPCompressedData cData = (PGPCompressedData)plainFact.nextObject();
    PGPObjectFactory pgpFact = new PGPObjectFactory(cData.getDataStream());
    Object message = pgpFact.nextObject();
    if (message instanceof PGPLiteralData)
    PGPLiteralData ld = (PGPLiteralData)message;
    FileOutputStream fOut = new FileOutputStream(ld.getFileName());
    System.out.println("\nLd.Getfilename: " + ld.getFileName());
    InputStream unc = ld.getInputStream();
    System.out.println(unc);
    int ch;
    while ((ch = unc.read()) >= 0)
    fOut.write(ch);
    fOut.flush();
    fOut.flush();
    fOut.close();
    System.out.println("\nfOut:" + fOut);
    System.out.println("\nPGPLiteralData yes");
    else if (message instanceof PGPOnePassSignatureList)
    throw new PGPException("encrypted message contains a signed message - not literal data.");
    else
    throw new PGPException("message is not a simple encrypted file - type unknown.");
    if (pbe.isIntegrityProtected())
    if (!pbe.verify())
    System.err.println("message failed integrity check");
    else
    System.err.println("message integrity check passed");
    else
    System.err.println("no message integrity check");
    catch (PGPException e)
    System.err.println(e);
    if (e.getUnderlyingException() != null)
    e.getUnderlyingException().printStackTrace();
    private static PGPPrivateKey findSecretKey(
    InputStream keyIn,
    long keyID,
    char[] pass)
    throws IOException, PGPException, NoSuchProviderException
    PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(
    PGPUtil.getDecoderStream(keyIn));
    PGPSecretKey pgpSecKey = pgpSec.getSecretKey(keyID);
    if (pgpSecKey == null)
    return null;
    return pgpSecKey.extractPrivateKey(pass, "BC");
    }

  • Basic stream/file/socket closing question

    If you create a stream, it's generally considered good practice to call close() on that stream once you're done with it. the same for files and sockets. My question is what happens if I don't keep a reference to the object that needs closing. For example:
    BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new File("myfile.txt")));Clearly, I can close() bis. But does doing so close the FileInputStream, and the File? OR, will those remain open until the garbage collecter gets around to closing them. If not, is it considered good practice to keep references around for the sole purpose of explicitly closing the resource so you don't have to wait for garbage collection?
    Finally, is it necessary to close() sockets/files/streams prior to calling System.exit()? It would save me a great deal of code in my exception handlers if I could simply exit() without explicitly freeing the resources I've opened prior to hitting the exception.
    Thanks.

    You should only need to call close on bis. That method call should take care of calling close on the underlying stream.

  • Question about web service client

    Hi,
    I am creating the a client to call non wls web serveice.
    First I need to create the client jar using clientgen. My question is when i create the client jar I need the wsdl file. where is the correct place to store the wsdl file? Also I have development and production wsdl file with the different service location. Do I have to store both of the wsdl files? It's a trouble to remember to build the different client jar for development and production (using different wsdl), is there anyway that I can build the client jar once and somehow dynamically configure to use different wsdl (ie service location) in different environment? Thanks

    Hi Holy,
    If you know the WSDL hasn't changed since you used it when running the clientgen Ant task, you can just use the one that is inside the JAR that clientgen produces. To do this, you just need to not specify an argument to the XXX_Impl constructor. For instance:
    AttachmentPartsService_Impl service = new AttachmentPartsService_Impl();
    This has some performance benefits, because it reduces the total number of network calls, the client-side Web Services stack makes. If you specify the URL for the WSDL to the constructor (as recommended by someone else here), the client-side Web Services stack will issue an HTTP GET to get it. Now if the WSDL that is returned uses types that are different than the ones the clientgen Ant task generated classes for (i.e. the ones in the JAR generated by the clientgen Ant task), you are in trouble because the client-side Web Services doesn't generate serialization/deserialization classes (i.e. the ones in the JAR generated by the clientgen Ant task) "on-the-fly".
    The service endpoint for a Web Service call can (and should) be set programmatically, from a properties or configuration file. This will look something like this in the code:
    import java.util.Properties;
    import javax.xml.rpc.Stub;
    private static Properties loadProperties(String fileName) throws IOException
    if (fileName == null || fileName.length() == 0) return null;
    Properties props = new Properties();
    FileInputStream fis = null;
    try
    fis = new FileInputStream(fileName);
    props.load(fis);
    finally
    if (fis != null) try { fis.close(); } catch (Exception ignore){}
    return props;
    public static void main() throws Exception
    Properties props = loadProperties("MyProperties.properties");
    Client client = new Client(props);
    public Client(Properties properties)
    AttachmentPartsService_Impl service = new AttachmentPartsService_Impl();
    AttachmentPartsServiceSoap port = service.getAttachmentPartsServiceSoap();
    if (schemeHostPort == null) schemeHostPort = "http://localhost:7001";
    ((AttachmentPartsServiceSoap_Stub)port)._setProperty(
    Stub.ENDPOINT_ADDRESS_PROPERTY,
    properties.getProperty("production.AttachmentPartsService.serviceEndpointURL"));
    This way, you can have a different properties file for each environment you propagate the web service to, as opposed to saving copies of WSDL files just to have the "correct" service endpoint address. It also has the additional benefit of letting you store the service endpoint URLs for more than just one web service.
    Regards,
    Mike Wooten

Maybe you are looking for

  • Ipad2 screen blank after ios 8 upgrade

    Screen blank, used the home and off button, still not working, a faint light comes on and nothing else - forced to reset factory settings, all data lost, a very upset daughter! all minecraft worlds created now gone! seems to be acknowledged by itunes

  • I will be returning my A505-S6005. Help me to avoid the restocking fee by reading this list.

    About five days ago I bought a Toshiba A505-S6005 laptop at Best Buy. I am so sorry I did because this computer has been a pain in the **bleep** since day one. I have numerous problems or errors with the unit, but the system still works (to a point)

  • HTTP Code:503

    Hi, My scenario is file->XI->Mail. yesterday it was running perfectly. Now it is giving following System error: <SAP:Category>XIServer</SAP:Category>   <SAP:Code area="INTERNAL">HTTP_RESP_STATUS_CODE_NOT_OK</SAP:Code>   <SAP:P1>503</SAP:P1>   <SAP:P2

  • Increment pattern in xsd..

    I need to define the schema for "val" attribute in the below XML: <data term="EXP"> <el val="20"> <ch> some data </ch> </el> <el val="21"> <ch> some data </ch> </el> .....similarly for val=22,23,24,....N </data> <data term="SUPP"> <el val="20"> <ch>

  • Stuck rental download

    Have a stuck itunes movie rental on ipad. Doesn't show up in rentals, only in the downloads tab of itunes on the ipad. Using up 5Gb in "other" need to get rid of the stuck download. Any ideas?