MCPcopy Create free account
hub / github.com/GateNLP/gate-core / getGateResourceAsByteArray

Method getGateResourceAsByteArray

src/main/java/gate/util/Files.java:312–342  ·  view source on GitHub ↗

Get a resource from the GATE resources directory as a byte array. The resource name should be relative to resourcePath which is equal with gate/resources ; e.g. for a resource stored as gate/resources/jape/Test11.jape , this method should be passed the name jape/Test

(String resourceName)

Source from the content-addressed store, hash-verified

310 * this method should be passed the name <TT>jape/Test11.jape</TT>.
311 */
312 public static byte[] getGateResourceAsByteArray(String resourceName)
313 throws IOException, IndexOutOfBoundsException, ArrayStoreException {
314
315 InputStream resourceInputStream = getGateResourceAsStream(resourceName);
316 BufferedInputStream resourceStream =
317 new BufferedInputStream(resourceInputStream);
318 byte b;
319 final int bufSize = 1024;
320 byte[] buf = new byte[bufSize];
321 int i = 0;
322
323 // get the whole resource into buf (expanding the array as needed)
324 while( (b = (byte) resourceStream.read()) != -1 ) {
325 if(i == buf.length) {
326 byte[] newBuf = new byte[buf.length * 2];
327 System.arraycopy (buf,0,newBuf,0,i);
328 buf = newBuf;
329 }
330 buf[i++] = b;
331 }
332
333 // close the resource stream
334 resourceStream.close();
335
336 // copy the contents of buf to an array of the correct size
337 byte[] bytes = new byte[i];
338
339 // copy from buf to bytes
340 System.arraycopy (buf,0,bytes,0,i);
341 return bytes;
342 } // getResourceGateAsByteArray(String)
343
344
345 /** Get a resource from the GATE ClassLoader as an InputStream.

Callers 1

testGetResourcesMethod · 0.95

Calls 3

readMethod · 0.65
closeMethod · 0.65

Tested by 1

testGetResourcesMethod · 0.76