< prev index next >

## src/com/sun/javatest/agent/AgentManager.java

Print this page

     521                     ref.write(in.readUTF());
     522                     break;
     523
     524                 case Agent.REF_FLUSH:
     525                     ref.write(in.readUTF());
     526                     ref.flush();
     527                     break;
     528                 }
     529             }
     530
     531             out.close();
     532             in.close();
     533             connection.close();
     534
     535             log.flush();
     536             ref.flush();
     537
     538             // might be better not to flush these ...
     539             for (Enumeration e = zips.keys(); e.hasMoreElements(); ) {
     540                 File f = (File)(e.nextElement());
     541                 ZipFile z = (ZipFile)(zips.get(f));
     542                 zips.remove(f);
     543                 z.close();
     544             }
     545
     546             return status;
     547         }
     548
     549         private AgentRemoteClassData locateClass(String name) {
     550             //System.err.println("locateClass: " + name);
     551             if (classPath != null) {
     552                 String cname = name.replace('.', '/') + ".class";
     553                 for (int i = 0; i < classPath.length; i++) {
     554                     byte[] data;
     555                     if (classPath[i].isDirectory())
     556                         data = readFromDir(cname, classPath[i]);
     557                     else
     558                         data = readFromJar(cname, classPath[i]);
     559                     if (data != null) {
     560                         String codeSource = "";
     561                         try {
     587             }
     588
     589             return null;
     590         }
     591
     592         private byte[] readFromDir(String name, File dir) {
     593             //System.err.println("readFromDir: " + name + " " + dir);
     594             try {
     595                 File file = new File(dir, name);
     596                 return read(new FileInputStream(file), ((int) file.length()));
     597             }
     598             catch (IOException e) {
     599                 //System.err.println("readFromDir: " + e);
     600                 return null;
     601             }
     602         }
     603
     604         private byte[] readFromJar(String name, File jarFile) {
     605             //System.err.println("readFromJar: " + name + " " + jarFile);
     606             try {
     607                 ZipFile z = (ZipFile)zips.get(jarFile);
     608                 if (z == null) {
     609                     z = new ZipFile(jarFile);
     610                     zips.put(jarFile, z);
     611                 }
     612                 ZipEntry ze = z.getEntry(name);
     613                 if (ze == null)
     614                     return null;
     615                 return read(z.getInputStream(ze), ((int) ze.getSize()));
     616             }
     617             catch (IOException e) {
     618                 //System.err.println("readFromJar: " + e);
     619                 return null;
     620             }
     621         }
     622
     623         private byte[] read(InputStream in, int size) throws IOException {
     624             //System.err.println("read: " + size);
     625             try {
     626                 byte data[] = new byte[size];
     627                 for (int total = 0; total < data.length; ) {
     628                     int n = in.read(data, total, data.length - total);
     629                     if (n > 0)
     630                         total += n;
     631                     else
     632                         throw new EOFException("unexpected end of file");
     633                 }
     634                 //System.err.println("read complete: " + data.length);
     635                 return data;
     636             }
     637             finally {
     638                 in.close();
     639             }
     640         }
     641
     642         private File[] split(String s) {
     643             char pathCh = File.pathSeparatorChar;
     644             Vector v = new Vector();
     645             int start = 0;
     646             for (int i = s.indexOf(pathCh); i != -1; i = s.indexOf(pathCh, start)) {
     647                 add(s.substring(start, i), v);
     648                 start = i + 1;
     649             }
     650             if (start != s.length())
     651                 add(s.substring(start), v);
     652             File[] path = new File[v.size()];
     653             v.copyInto(path);
     654             return path;
     655         }
     656
     657         private void add(String s, Vector v) {
     658             if (s.length() != 0)
     659                 v.addElement(new File(s));
     660         }
     661
     662         private Connection connection;
     663         private DataInputStream in;
     664         private DataOutputStream out;
     665
     666         private File[] classPath;
     667         private boolean sharedCl;
     668         private int timeout = 0;
     669         private Hashtable zips = new Hashtable();
     670     }
     671
     672 }
     673
     521                     ref.write(in.readUTF());
     522                     break;
     523
     524                 case Agent.REF_FLUSH:
     525                     ref.write(in.readUTF());
     526                     ref.flush();
     527                     break;
     528                 }
     529             }
     530
     531             out.close();
     532             in.close();
     533             connection.close();
     534
     535             log.flush();
     536             ref.flush();
     537
     538             // might be better not to flush these ...
     539             for (Enumeration e = zips.keys(); e.hasMoreElements(); ) {
     540                 File f = (File)(e.nextElement());
     541                 ZipFile z = zips.get(f);
     542                 zips.remove(f);
     543                 z.close();
     544             }
     545
     546             return status;
     547         }
     548
     549         private AgentRemoteClassData locateClass(String name) {
     550             //System.err.println("locateClass: " + name);
     551             if (classPath != null) {
     552                 String cname = name.replace('.', '/') + ".class";
     553                 for (int i = 0; i < classPath.length; i++) {
     554                     byte[] data;
     555                     if (classPath[i].isDirectory())
     556                         data = readFromDir(cname, classPath[i]);
     557                     else
     558                         data = readFromJar(cname, classPath[i]);
     559                     if (data != null) {
     560                         String codeSource = "";
     561                         try {
     587             }
     588
     589             return null;
     590         }
     591
     592         private byte[] readFromDir(String name, File dir) {
     593             //System.err.println("readFromDir: " + name + " " + dir);
     594             try {
     595                 File file = new File(dir, name);
     596                 return read(new FileInputStream(file), ((int) file.length()));
     597             }
     598             catch (IOException e) {
     599                 //System.err.println("readFromDir: " + e);
     600                 return null;
     601             }
     602         }
     603
     604         private byte[] readFromJar(String name, File jarFile) {
     605             //System.err.println("readFromJar: " + name + " " + jarFile);
     606             try {
     607                 ZipFile z = zips.get(jarFile);
     608                 if (z == null) {
     609                     z = new ZipFile(jarFile);
     610                     zips.put(jarFile, z);
     611                 }
     612                 ZipEntry ze = z.getEntry(name);
     613                 if (ze == null)
     614                     return null;
     615                 return read(z.getInputStream(ze), ((int) ze.getSize()));
     616             }
     617             catch (IOException e) {
     618                 //System.err.println("readFromJar: " + e);
     619                 return null;
     620             }
     621         }
     622
     623         private byte[] read(InputStream in, int size) throws IOException {
     624             //System.err.println("read: " + size);
     625             try {
     626                 byte data[] = new byte[size];
     627                 for (int total = 0; total < data.length; ) {
     628                     int n = in.read(data, total, data.length - total);
     629                     if (n > 0)
     630                         total += n;
     631                     else
     632                         throw new EOFException("unexpected end of file");
     633                 }
     634                 //System.err.println("read complete: " + data.length);
     635                 return data;
     636             }
     637             finally {
     638                 in.close();
     639             }
     640         }
     641
     642         private File[] split(String s) {
     643             char pathCh = File.pathSeparatorChar;
     644             Vector<File> v = new Vector<>();
     645             int start = 0;
     646             for (int i = s.indexOf(pathCh); i != -1; i = s.indexOf(pathCh, start)) {
     647                 add(s.substring(start, i), v);
     648                 start = i + 1;
     649             }
     650             if (start != s.length())
     651                 add(s.substring(start), v);
     652             File[] path = new File[v.size()];
     653             v.copyInto(path);
     654             return path;
     655         }
     656
     657         private void add(String s, Vector<File> v) {
     658             if (s.length() != 0)
     659                 v.addElement(new File(s));
     660         }
     661
     662         private Connection connection;
     663         private DataInputStream in;
     664         private DataOutputStream out;
     665
     666         private File[] classPath;
     667         private boolean sharedCl;
     668         private int timeout = 0;
     669         private Hashtable<File, ZipFile> zips = new Hashtable<>();
     670     }
     671
     672 }
     673

< prev index next >