public OpenSlide(File file) throws IOException { if (!file.exists()) { throw new FileNotFoundException(file.toString()); } // vartika on 5 august filePath = file.getPath(); osr = OpenSlideJNI.openslide_open(file.getPath()); if (osr == 0) { throw new IOException(file + ": Not a file that OpenSlide can recognize"); } // dispose on error, we are in the constructor try { checkError(); } catch (IOException e) { dispose(); throw e; } // store level count levelCount = OpenSlideJNI.openslide_get_level_count(osr); // store dimensions levelWidths = new long[levelCount]; levelHeights = new long[levelCount]; levelDownsamples = new double[levelCount]; for (int i = 0; i < levelCount; i++) { long dim[] = new long[2]; OpenSlideJNI.openslide_get_level_dimensions(osr, i, dim); levelWidths[i] = dim[0]; levelHeights[i] = dim[1]; levelDownsamples[i] = OpenSlideJNI.openslide_get_level_downsample(osr, i); } // properties HashMap<String, String> props = new HashMap<String, String>(); for (String s : OpenSlideJNI.openslide_get_property_names(osr)) { props.put(s, OpenSlideJNI.openslide_get_property_value(osr, s)); } properties = Collections.unmodifiableMap(props); // associated images HashMap<String, AssociatedImage> associated = new HashMap<String, AssociatedImage>(); for (String s : OpenSlideJNI.openslide_get_associated_image_names(osr)) { associated.put(s, new AssociatedImage(s, this)); } associatedImages = Collections.unmodifiableMap(associated); // store info for hash and equals canonicalFile = file.getCanonicalFile(); String quickhash1 = getProperties().get(PROPERTY_NAME_QUICKHASH1); if (quickhash1 != null) { hashCodeVal = (int) Long.parseLong(quickhash1.substring(0, 8), 16); } else { hashCodeVal = canonicalFile.hashCode(); } // dispose on error, we are in the constructor try { checkError(); } catch (IOException e) { dispose(); throw e; } }