/** * Load in index from the specified stream. Note that the caller is responsible for decompressing the stream if necessary. * * @param source the stream source (typically the file name) * @param inputStream the raw byte stream of the index */ public static Index loadIndex(final String source, final InputStream inputStream) { // Must be buffered, because getIndexType uses mark and reset try (BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream, Defaults.NON_ZERO_BUFFER_SIZE)) { final Class<Index> indexClass = IndexType.getIndexType(bufferedInputStream).getIndexType(); final Constructor<Index> ctor = indexClass.getConstructor(InputStream.class); return ctor.newInstance(bufferedInputStream); } catch (final TribbleException ex) { throw ex; } catch (final InvocationTargetException ex) { if (ex.getCause() instanceof EOFException) { throw new TribbleException.CorruptedIndexFile("Index file is corrupted", source, ex); } throw new RuntimeException(ex); } catch (final Exception ex) { throw new RuntimeException(ex); } }
/** * Load in index from the specified stream. Note that the caller is responsible for decompressing the stream if necessary. * * @param source the stream source (typically the file name) * @param inputStream the raw byte stream of the index */ public static Index loadIndex(final String source, final InputStream inputStream) { // Must be buffered, because getIndexType uses mark and reset try (BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream, Defaults.NON_ZERO_BUFFER_SIZE)) { final Class<Index> indexClass = IndexType.getIndexType(bufferedInputStream).getIndexType(); final Constructor<Index> ctor = indexClass.getConstructor(InputStream.class); return ctor.newInstance(bufferedInputStream); } catch (final TribbleException ex) { throw ex; } catch (final InvocationTargetException ex) { if (ex.getCause() instanceof EOFException) { throw new TribbleException.CorruptedIndexFile("Index file is corrupted", source, ex); } throw new RuntimeException(ex); } catch (final Exception ex) { throw new RuntimeException(ex); } }