1 package org.simantics.scl.osgi.internal;
3 import java.io.IOException;
4 import java.io.InputStream;
6 import java.nio.charset.Charset;
7 import java.util.Arrays;
9 import org.osgi.framework.Bundle;
10 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory;
13 public class BundleDocumentationSource {
15 private static final Logger LOGGER = LoggerFactory.getLogger(BundleDocumentationSource.class);
17 public static final Charset UTF8 = Charset.forName("UTF-8");
19 public final String documentationName;
20 public final Bundle bundle;
23 public BundleDocumentationSource(String documentationName, Bundle bundle,
25 this.documentationName = documentationName;
30 public String getText() {
32 InputStream stream = url.openStream();
34 byte[] buffer = new byte[1024];
37 int count = stream.read(buffer, pos, buffer.length-pos);
41 if(pos == buffer.length)
42 buffer = Arrays.copyOf(buffer, buffer.length*2);
44 return new String(buffer, 0, pos, UTF8);
48 } catch(IOException e) {
49 LOGGER.error("Could not get text for {} at {}", documentationName, url);