|
64 | 64 | import org.knime.core.data.filestore.FileStoreCell; |
65 | 65 | import org.knime.knip.base.KNIMEKNIPPlugin; |
66 | 66 | import org.knime.knip.base.data.CachedObjectAccess; |
67 | | -import org.knime.knip.base.data.CachedObjectAccess.StreamSkipper; |
68 | 67 | import org.knime.knip.base.data.FileStoreCellMetadata; |
69 | 68 | import org.knime.knip.base.data.IntervalValue; |
70 | 69 | import org.knime.knip.base.renderer.ThumbnailRenderer; |
|
75 | 74 | import org.knime.knip.core.awt.labelingcolortable.RandomMissingColorHandler; |
76 | 75 | import org.knime.knip.core.data.LabelingView; |
77 | 76 | import org.knime.knip.core.data.img.LabelingMetadata; |
78 | | -import org.knime.knip.core.io.externalization.BufferedDataInputStream; |
79 | 77 | import org.knime.knip.core.io.externalization.ExternalizerManager; |
80 | 78 | import org.scijava.Named; |
81 | 79 | import org.scijava.cache.CacheService; |
@@ -156,9 +154,9 @@ protected LabelingCell(final RandomAccessibleInterval<LabelingType<L>> labeling, |
156 | 154 | super(fileStore); |
157 | 155 | final long[] dimensions = new long[labeling.numDimensions()]; |
158 | 156 | labeling.dimensions(dimensions); |
159 | | - m_metadataAccess = new CachedObjectAccess<LabelingCellMetadata>(fileStore, |
| 157 | + m_metadataAccess = new CachedObjectAccess<>(fileStore, |
160 | 158 | new LabelingCellMetadata(metadata, Views.iterable(labeling).size(), dimensions, null)); |
161 | | - m_labelingAccess = new CachedObjectAccess<>(fileStore, new LabelingView<L>(labeling)); |
| 159 | + m_labelingAccess = new CachedObjectAccess<>(fileStore, new LabelingView<>(labeling)); |
162 | 160 | m_fileMetadata = new FileStoreCellMetadata(-1, false, null); |
163 | 161 |
|
164 | 162 | CACHE.put(this.stringHashCode(), this); |
@@ -365,7 +363,7 @@ public synchronized Image getThumbnail(final RenderingHints renderingHints) { |
365 | 363 | fullHeight = tmp.getDimensions()[1]; |
366 | 364 | } |
367 | 365 | if ((tmp.getThumbnail() == null) || (tmp.getThumbnail().getHeight() != height)) { |
368 | | - m_metadataAccess = new CachedObjectAccess<LabelingCellMetadata>(getFileStore(), |
| 366 | + m_metadataAccess = new CachedObjectAccess<>(getFileStore(), |
369 | 367 | tmp = new LabelingCellMetadata(tmp.getLabelingMetadata(), tmp.getSize(), tmp.getDimensions(), |
370 | 368 | createThumbnail(height / fullHeight))); |
371 | 369 | // update cached object |
@@ -428,27 +426,20 @@ protected synchronized void load(final DataInput input) throws IOException { |
428 | 426 | protected void postConstruct() { |
429 | 427 |
|
430 | 428 | @SuppressWarnings("unchecked") |
431 | | - final LabelingCell<L> tmp = (LabelingCell<L>)CACHE.get(this); |
| 429 | + final LabelingCell<L> tmp = (LabelingCell<L>)CACHE.get(this.stringHashCode()); |
432 | 430 |
|
433 | 431 | if (tmp == null) { |
434 | 432 | // Creates empty CachedObjectAccesses which know how to reconstruct the managed objects. |
435 | 433 | m_metadataAccess = new CachedObjectAccess<>(getFileStore(), null, m_fileMetadata.getOffset(), null); |
436 | | - m_labelingAccess = |
437 | | - new CachedObjectAccess<>(getFileStore(), null, m_fileMetadata.getOffset(), new StreamSkipper() { |
438 | | - /** |
439 | | - * {@inheritDoc} |
440 | | - */ |
441 | | - @Override |
442 | | - public void skip(final BufferedDataInputStream in) { |
443 | | - try { |
444 | | - m_metadataAccess.setObject(ExternalizerManager.read(in)); |
445 | | - } catch (Exception e) { |
446 | | - throw new RuntimeException(e); |
447 | | - } |
448 | | - } |
449 | | - }); |
450 | | - |
451 | | - CACHE.put(this, this); |
| 434 | + m_labelingAccess = new CachedObjectAccess<>(getFileStore(), null, m_fileMetadata.getOffset(), in -> { |
| 435 | + try { |
| 436 | + m_metadataAccess.setObject(ExternalizerManager.read(in)); |
| 437 | + } catch (Exception e) { |
| 438 | + throw new RuntimeException(e); |
| 439 | + } |
| 440 | + }); |
| 441 | + |
| 442 | + CACHE.put(this.stringHashCode(), this); |
452 | 443 | } else { |
453 | 444 | m_labelingAccess = tmp.m_labelingAccess; |
454 | 445 | m_metadataAccess = tmp.m_metadataAccess; |
|
0 commit comments