1 11 12 package org.eclipse.osgi.baseadaptor.bundlefile; 13 14 import java.io.*; 15 import java.net.URL ; 16 import org.eclipse.osgi.framework.debug.Debug; 17 18 25 public abstract class BundleEntry { 26 protected static final int BUF_SIZE = 8 * 1024; 27 33 public abstract InputStream getInputStream() throws IOException; 34 35 40 public abstract long getSize(); 41 42 47 public abstract String getName(); 48 49 56 public abstract long getTime(); 57 58 63 public abstract URL getLocalURL(); 64 65 71 public abstract URL getFileURL(); 72 73 78 public String toString() { 79 return (getName()); 80 } 81 82 88 public byte[] getBytes() throws IOException{ 89 InputStream in = getInputStream(); 90 int length = (int) getSize(); 91 byte[] classbytes; 92 int bytesread = 0; 93 int readcount; 94 if (Debug.DEBUG && Debug.DEBUG_LOADER) 95 Debug.println(" about to read " + length + " bytes from " + getName()); 97 try { 98 if (length > 0) { 99 classbytes = new byte[length]; 100 for (; bytesread < length; bytesread += readcount) { 101 readcount = in.read(classbytes, bytesread, length - bytesread); 102 if (readcount <= 0) 103 break; 104 } 105 } else { 106 length = BUF_SIZE; 107 classbytes = new byte[length]; 108 readloop: while (true) { 109 for (; bytesread < length; bytesread += readcount) { 110 readcount = in.read(classbytes, bytesread, length - bytesread); 111 if (readcount <= 0) 112 break readloop; 113 } 114 byte[] oldbytes = classbytes; 115 length += BUF_SIZE; 116 classbytes = new byte[length]; 117 System.arraycopy(oldbytes, 0, classbytes, 0, bytesread); 118 } 119 } 120 if (classbytes.length > bytesread) { 121 byte[] oldbytes = classbytes; 122 classbytes = new byte[bytesread]; 123 System.arraycopy(oldbytes, 0, classbytes, 0, bytesread); 124 } 125 } finally { 126 try { 127 in.close(); 128 } catch (IOException ee) { 129 } 131 } 132 return classbytes; 133 } 134 } 135 | Popular Tags |