1 package org.simantics.scl.osgi.internal;
\r
3 import java.io.IOException;
\r
4 import java.io.InputStream;
\r
6 import java.nio.charset.Charset;
\r
7 import java.util.Arrays;
\r
9 import org.osgi.framework.Bundle;
\r
11 public class BundleDocumentationSource {
\r
12 public static final Charset UTF8 = Charset.forName("UTF-8");
\r
14 public final String documentationName;
\r
15 public final Bundle bundle;
\r
16 public final URL url;
\r
18 public BundleDocumentationSource(String documentationName, Bundle bundle,
\r
20 this.documentationName = documentationName;
\r
21 this.bundle = bundle;
\r
25 public String getText() {
\r
27 InputStream stream = url.openStream();
\r
29 byte[] buffer = new byte[1024];
\r
32 int count = stream.read(buffer, pos, buffer.length-pos);
\r
36 if(pos == buffer.length)
\r
37 buffer = Arrays.copyOf(buffer, buffer.length*2);
\r
39 return new String(buffer, 0, pos, UTF8);
\r
43 } catch(IOException e) {
\r
44 e.printStackTrace();
\r