-package org.simantics.scl.osgi.internal;\r
-\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
-import java.net.URL;\r
-import java.nio.charset.Charset;\r
-import java.util.Arrays;\r
-\r
-import org.osgi.framework.Bundle;\r
-\r
-public class BundleDocumentationSource {\r
- public static final Charset UTF8 = Charset.forName("UTF-8"); \r
- \r
- public final String documentationName;\r
- public final Bundle bundle;\r
- public final URL url;\r
- \r
- public BundleDocumentationSource(String documentationName, Bundle bundle,\r
- URL url) {\r
- this.documentationName = documentationName;\r
- this.bundle = bundle;\r
- this.url = url;\r
- }\r
-\r
- public String getText() {\r
- try {\r
- InputStream stream = url.openStream();\r
- try {\r
- byte[] buffer = new byte[1024];\r
- int pos = 0;\r
- while(true) {\r
- int count = stream.read(buffer, pos, buffer.length-pos);\r
- if(count <= 0)\r
- break;\r
- pos += count;\r
- if(pos == buffer.length)\r
- buffer = Arrays.copyOf(buffer, buffer.length*2);\r
- }\r
- return new String(buffer, 0, pos, UTF8);\r
- } finally {\r
- stream.close();\r
- }\r
- } catch(IOException e) {\r
- e.printStackTrace();\r
- return null;\r
- }\r
- }\r
-}\r
+package org.simantics.scl.osgi.internal;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.nio.charset.Charset;
+import java.util.Arrays;
+
+import org.osgi.framework.Bundle;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class BundleDocumentationSource {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(BundleDocumentationSource.class);
+
+ public static final Charset UTF8 = Charset.forName("UTF-8");
+
+ public final String documentationName;
+ public final Bundle bundle;
+ public final URL url;
+
+ public BundleDocumentationSource(String documentationName, Bundle bundle,
+ URL url) {
+ this.documentationName = documentationName;
+ this.bundle = bundle;
+ this.url = url;
+ }
+
+ public String getText() {
+ try {
+ InputStream stream = url.openStream();
+ try {
+ byte[] buffer = new byte[1024];
+ int pos = 0;
+ while(true) {
+ int count = stream.read(buffer, pos, buffer.length-pos);
+ if(count <= 0)
+ break;
+ pos += count;
+ if(pos == buffer.length)
+ buffer = Arrays.copyOf(buffer, buffer.length*2);
+ }
+ return new String(buffer, 0, pos, UTF8);
+ } finally {
+ stream.close();
+ }
+ } catch(IOException e) {
+ LOGGER.error("Could not get text for {} at {}", documentationName, url);
+ return null;
+ }
+ }
+}