+ private static FormatHandler<TransferableGraph1> FORMAT_HANDLER = new FormatHandler<TransferableGraph1>() {
+ @Override
+ public Binding getBinding() {
+ return TransferableGraph1.BINDING;
+ }
+ @Override
+ public TransferableGraph1 process(DataContainer container) throws Exception {
+ return (TransferableGraph1) container.content.getValue(TransferableGraph1.BINDING);
+ }
+ };
+
+ @SuppressWarnings("unchecked")
+ private static Map<String, FormatHandler<TransferableGraph1>> handlers = ArrayMap.make(
+ new String[] {
+ "graph:1",
+ "sharedLibrary:1"
+ },
+ FORMAT_HANDLER,
+ FORMAT_HANDLER);
+
+ private static TransferableGraph1 readTG(InputStream is) throws Exception {
+ // For an unknown reason this is totally broken when running the TestSCLOsgi
+ // in the SDK Tycho build. It returns incomplete results because the
+ // ReadableByteChannel used by ByteFileReader starts returning 0 unexpectedly.
+// try (TransferableGraphFileReader reader = new TransferableGraphFileReader(is)) {
+// return reader.readTG();
+// }
+ return DataContainers.readFile(new DataInputStream(is), handlers);
+ }
+
+ private static TransferableGraph1 readTG(URL url) throws Exception {
+ try (InputStream is = url.openStream()) {
+ return readTG(is);
+ }
+ }
+
+ private static DataContainer readHeader(URL url) throws IOException {
+ try (InputStream is = url.openStream()) {
+ return DataContainers.readHeader(new DataInputStream(new BufferedInputStream(is, 1 << 14)));
+ }
+ }
+
+ private static Integer readCachedHash(URL url) throws IOException, AdaptException {
+ DataContainer header = readHeader(url);
+ Variant hashCode = header.metadata.get(Extensions.CACHED_HASHCODE);
+ return hashCode != null ? (Integer) hashCode.getValue(Bindings.INTEGER) : null;
+ }
+
+ private static Version toP2Version(Bundle bundle) {
+ org.osgi.framework.Version osgiVersion = bundle.getVersion();
+ return Version.createOSGi(osgiVersion.getMajor(), osgiVersion.getMinor(), osgiVersion.getMicro(), osgiVersion.getQualifier());
+ }
+
+ private static String getBundleName(Bundle bundle, String id) {
+ String name = (String) bundle.getHeaders().get("Bundle-Name");
+ return name != null ? name : id;
+ }
+
+ private static boolean isImmutable(Bundle bundle) {
+ String immutable = (String) bundle.getHeaders().get("Immutable");
+ return immutable != null ? "true".equals(immutable) : true;
+ }
+