@Test public final void testARCGetResource() throws Exception { long length = 7109; long offset = 6865980; String name = "http: HarvestResourceDTO dto = new ArcHarvestResourceDTO(targetInstanceOid, harvestResultNumber, 54321, name, length, offset, 0, TestCARC, 200, true); File res = testInstance.getResource(new Long(targetInstanceOid).toString(), harvestResultNumber, dto); assertTrue(res != null); assertTrue(res.length() == length); }
@SuppressWarnings("finally") public File getResource(String targetInstanceName, int harvestResultNumber, HarvestResourceDTO resourcex) throws DigitalAssetStoreException { FileOutputStream fos = null; ArchiveReader reader = null; ArchiveRecord record = null; File source = null; File dest = null; ArcHarvestResourceDTO resource = null; try { resource = (ArcHarvestResourceDTO) resourcex; source = new File(this.baseDir, "/" + targetInstanceName + "/" + harvestResultNumber + "/" + resource.getArcFileName()); try { reader = ArchiveReaderFactory.get(source); } catch (IOException ex) { if (log.isWarnEnabled()) { log.warn("Failed to get resource : " + ex.getMessage()); } source = new File(fileArchive.getArchiveRepository() + "/" + targetInstanceName + "/" + fileArchive.getArchiveArcDirectory() + "/" + resource.getArcFileName()); if (log.isWarnEnabled()) { log.info("trying filestore " + source.getAbsolutePath()); } try { reader = ArchiveReaderFactory.get(source); } catch (IOException e) { throw new DigitalAssetStoreException( "Failed to get resource : " + e.getMessage()); } } record = reader.get(resource.getResourceOffset()); dest = File.createTempFile("wct", "tmp"); if (log.isDebugEnabled()) { log.debug("== Temp file: " + dest.getAbsolutePath()); } fos = new FileOutputStream(dest); if (record instanceof ARCRecord) { ((ARCRecord) record).skipHttpHeader(); } else { skipStatusLine(record); skipHeaders(record); } int bytesRead = 0; byte[] byteBuffer = new byte[BYTE_BUFF_SIZE]; while ((bytesRead = record.read(byteBuffer, 0, BYTE_BUFF_SIZE)) != -1) { fos.write(byteBuffer, 0, bytesRead); } if (fos != null) fos.close(); } catch (IOException e) { if (log.isErrorEnabled()) { log.error("Failed to get resource : " + e.getMessage(), e); } throw new DigitalAssetStoreException("Failed to get resource : " + e.getMessage()); } catch (RuntimeException ex) { if (log.isErrorEnabled()) { log.error("Failed to get resource : " + ex.getMessage(), ex); } throw new DigitalAssetStoreException("Failed to get resource : " + ex.getMessage()); } finally { try { if (fos != null) fos.close(); } catch (Exception ex) { if (log.isErrorEnabled()) { log.error("close fos failed " + ex.getMessage(), ex); } } try { if (record != null) record.close(); } catch (Exception ex) { if (log.isErrorEnabled()) { log.error("close record failed " + ex.getMessage(), ex); } } try { if (reader != null) reader.close(); } catch (Exception ex) { if (log.isErrorEnabled()) { log.error("close reader failed " + ex.getMessage(), ex); } } } return dest; }
ArcDigitalAssetStoreService implements DigitalAssetStore,
        LogProvider { @SuppressWarnings("finally") public File getResource(String targetInstanceName, int harvestResultNumber, HarvestResourceDTO resourcex) throws DigitalAssetStoreException { FileOutputStream fos = null; ArchiveReader reader = null; ArchiveRecord record = null; File source = null; File dest = null; ArcHarvestResourceDTO resource = null; try { resource = (ArcHarvestResourceDTO) resourcex; source = new File(this.baseDir, "/" + targetInstanceName + "/" + harvestResultNumber + "/" + resource.getArcFileName()); try { reader = ArchiveReaderFactory.get(source); } catch (IOException ex) { if (log.isWarnEnabled()) { log.warn("Failed to get resource : " + ex.getMessage()); } source = new File(fileArchive.getArchiveRepository() + "/" + targetInstanceName + "/" + fileArchive.getArchiveArcDirectory() + "/" + resource.getArcFileName()); if (log.isWarnEnabled()) { log.info("trying filestore " + source.getAbsolutePath()); } try { reader = ArchiveReaderFactory.get(source); } catch (IOException e) { throw new DigitalAssetStoreException( "Failed to get resource : " + e.getMessage()); } } record = reader.get(resource.getResourceOffset()); dest = File.createTempFile("wct", "tmp"); if (log.isDebugEnabled()) { log.debug("== Temp file: " + dest.getAbsolutePath()); } fos = new FileOutputStream(dest); if (record instanceof ARCRecord) { ((ARCRecord) record).skipHttpHeader(); } else { skipStatusLine(record); skipHeaders(record); } int bytesRead = 0; byte[] byteBuffer = new byte[BYTE_BUFF_SIZE]; while ((bytesRead = record.read(byteBuffer, 0, BYTE_BUFF_SIZE)) != -1) { fos.write(byteBuffer, 0, bytesRead); } if (fos != null) fos.close(); } catch (IOException e) { if (log.isErrorEnabled()) { log.error("Failed to get resource : " + e.getMessage(), e); } throw new DigitalAssetStoreException("Failed to get resource : " + e.getMessage()); } catch (RuntimeException ex) { if (log.isErrorEnabled()) { log.error("Failed to get resource : " + ex.getMessage(), ex); } throw new DigitalAssetStoreException("Failed to get resource : " + ex.getMessage()); } finally { try { if (fos != null) fos.close(); } catch (Exception ex) { if (log.isErrorEnabled()) { log.error("close fos failed " + ex.getMessage(), ex); } } try { if (record != null) record.close(); } catch (Exception ex) { if (log.isErrorEnabled()) { log.error("close record failed " + ex.getMessage(), ex); } } try { if (reader != null) reader.close(); } catch (Exception ex) { if (log.isErrorEnabled()) { log.error("close reader failed " + ex.getMessage(), ex); } } } return dest; } }
ArcDigitalAssetStoreService implements DigitalAssetStore,
        LogProvider { @SuppressWarnings("finally") public File getResource(String targetInstanceName, int harvestResultNumber, HarvestResourceDTO resourcex) throws DigitalAssetStoreException { FileOutputStream fos = null; ArchiveReader reader = null; ArchiveRecord record = null; File source = null; File dest = null; ArcHarvestResourceDTO resource = null; try { resource = (ArcHarvestResourceDTO) resourcex; source = new File(this.baseDir, "/" + targetInstanceName + "/" + harvestResultNumber + "/" + resource.getArcFileName()); try { reader = ArchiveReaderFactory.get(source); } catch (IOException ex) { if (log.isWarnEnabled()) { log.warn("Failed to get resource : " + ex.getMessage()); } source = new File(fileArchive.getArchiveRepository() + "/" + targetInstanceName + "/" + fileArchive.getArchiveArcDirectory() + "/" + resource.getArcFileName()); if (log.isWarnEnabled()) { log.info("trying filestore " + source.getAbsolutePath()); } try { reader = ArchiveReaderFactory.get(source); } catch (IOException e) { throw new DigitalAssetStoreException( "Failed to get resource : " + e.getMessage()); } } record = reader.get(resource.getResourceOffset()); dest = File.createTempFile("wct", "tmp"); if (log.isDebugEnabled()) { log.debug("== Temp file: " + dest.getAbsolutePath()); } fos = new FileOutputStream(dest); if (record instanceof ARCRecord) { ((ARCRecord) record).skipHttpHeader(); } else { skipStatusLine(record); skipHeaders(record); } int bytesRead = 0; byte[] byteBuffer = new byte[BYTE_BUFF_SIZE]; while ((bytesRead = record.read(byteBuffer, 0, BYTE_BUFF_SIZE)) != -1) { fos.write(byteBuffer, 0, bytesRead); } if (fos != null) fos.close(); } catch (IOException e) { if (log.isErrorEnabled()) { log.error("Failed to get resource : " + e.getMessage(), e); } throw new DigitalAssetStoreException("Failed to get resource : " + e.getMessage()); } catch (RuntimeException ex) { if (log.isErrorEnabled()) { log.error("Failed to get resource : " + ex.getMessage(), ex); } throw new DigitalAssetStoreException("Failed to get resource : " + ex.getMessage()); } finally { try { if (fos != null) fos.close(); } catch (Exception ex) { if (log.isErrorEnabled()) { log.error("close fos failed " + ex.getMessage(), ex); } } try { if (record != null) record.close(); } catch (Exception ex) { if (log.isErrorEnabled()) { log.error("close record failed " + ex.getMessage(), ex); } } try { if (reader != null) reader.close(); } catch (Exception ex) { if (log.isErrorEnabled()) { log.error("close reader failed " + ex.getMessage(), ex); } } } return dest; }  }
ArcDigitalAssetStoreService implements DigitalAssetStore,
        LogProvider { @SuppressWarnings("finally") public File getResource(String targetInstanceName, int harvestResultNumber, HarvestResourceDTO resourcex) throws DigitalAssetStoreException { FileOutputStream fos = null; ArchiveReader reader = null; ArchiveRecord record = null; File source = null; File dest = null; ArcHarvestResourceDTO resource = null; try { resource = (ArcHarvestResourceDTO) resourcex; source = new File(this.baseDir, "/" + targetInstanceName + "/" + harvestResultNumber + "/" + resource.getArcFileName()); try { reader = ArchiveReaderFactory.get(source); } catch (IOException ex) { if (log.isWarnEnabled()) { log.warn("Failed to get resource : " + ex.getMessage()); } source = new File(fileArchive.getArchiveRepository() + "/" + targetInstanceName + "/" + fileArchive.getArchiveArcDirectory() + "/" + resource.getArcFileName()); if (log.isWarnEnabled()) { log.info("trying filestore " + source.getAbsolutePath()); } try { reader = ArchiveReaderFactory.get(source); } catch (IOException e) { throw new DigitalAssetStoreException( "Failed to get resource : " + e.getMessage()); } } record = reader.get(resource.getResourceOffset()); dest = File.createTempFile("wct", "tmp"); if (log.isDebugEnabled()) { log.debug("== Temp file: " + dest.getAbsolutePath()); } fos = new FileOutputStream(dest); if (record instanceof ARCRecord) { ((ARCRecord) record).skipHttpHeader(); } else { skipStatusLine(record); skipHeaders(record); } int bytesRead = 0; byte[] byteBuffer = new byte[BYTE_BUFF_SIZE]; while ((bytesRead = record.read(byteBuffer, 0, BYTE_BUFF_SIZE)) != -1) { fos.write(byteBuffer, 0, bytesRead); } if (fos != null) fos.close(); } catch (IOException e) { if (log.isErrorEnabled()) { log.error("Failed to get resource : " + e.getMessage(), e); } throw new DigitalAssetStoreException("Failed to get resource : " + e.getMessage()); } catch (RuntimeException ex) { if (log.isErrorEnabled()) { log.error("Failed to get resource : " + ex.getMessage(), ex); } throw new DigitalAssetStoreException("Failed to get resource : " + ex.getMessage()); } finally { try { if (fos != null) fos.close(); } catch (Exception ex) { if (log.isErrorEnabled()) { log.error("close fos failed " + ex.getMessage(), ex); } } try { if (record != null) record.close(); } catch (Exception ex) { if (log.isErrorEnabled()) { log.error("close record failed " + ex.getMessage(), ex); } } try { if (reader != null) reader.close(); } catch (Exception ex) { if (log.isErrorEnabled()) { log.error("close reader failed " + ex.getMessage(), ex); } } } return dest; }  void save(String targetInstanceName, String directory, File file); void save(String targetInstanceName, String directory, File[] files); void save(String targetInstanceName, File[] files); void save(String targetInstanceName, File file); @SuppressWarnings("finally") File getResource(String targetInstanceName, int harvestResultNumber,
                            HarvestResourceDTO resourcex); byte[] getSmallResource(String targetInstanceName,
                                   int harvestResultNumber, HarvestResourceDTO resourcex); Header[] getHeaders(String targetInstanceName,
                               int harvestResultNumber, HarvestResourceDTO resourcex); HarvestResultDTO copyAndPrune(String targetInstanceName,
                                         int orgHarvestResultNum, int newHarvestResultNum,
                                         List<String> urisToDelete, List<HarvestResourceDTO> hrsToImport); File getLogFile(String aJob, String aFileName); List<String> getLogFileNames(String aJob); LogFilePropertiesDTO[] getLogFileAttributes(String aJob); void purge(String[] targetInstanceNames); void purgeAbortedTargetInstances(String[] targetInstanceNames); void submitToArchive(String targetInstanceOid, String SIP,
                                Map xAttributes, int harvestNumber); CustomDepositFormResultDTO getCustomDepositFormDetails(
            CustomDepositFormCriteriaDTO criteria); void setArchive(Archive archive); void setBaseDir(String baseDir); void initiateIndexing(ArcHarvestResultDTO harvestResult); void initiateRemoveIndexes(ArcHarvestResultDTO harvestResult); Boolean checkIndexing(Long harvestResultOid); void setIndexer(Indexer indexer); void setDasFileMover(DasFileMover fileMover); void setWsEndPoint(WebServiceEndPoint wsEndPoint); void setPageImagePrefix(String pageImagePrefix); String getPageImagePrefix(); void setAqaReportPrefix(String aqaReportPrefix); String getAqaReportPrefix(); void setFileArchive(FileArchive fileArchive); }
ArcDigitalAssetStoreService implements DigitalAssetStore,
        LogProvider { @SuppressWarnings("finally") public File getResource(String targetInstanceName, int harvestResultNumber, HarvestResourceDTO resourcex) throws DigitalAssetStoreException { FileOutputStream fos = null; ArchiveReader reader = null; ArchiveRecord record = null; File source = null; File dest = null; ArcHarvestResourceDTO resource = null; try { resource = (ArcHarvestResourceDTO) resourcex; source = new File(this.baseDir, "/" + targetInstanceName + "/" + harvestResultNumber + "/" + resource.getArcFileName()); try { reader = ArchiveReaderFactory.get(source); } catch (IOException ex) { if (log.isWarnEnabled()) { log.warn("Failed to get resource : " + ex.getMessage()); } source = new File(fileArchive.getArchiveRepository() + "/" + targetInstanceName + "/" + fileArchive.getArchiveArcDirectory() + "/" + resource.getArcFileName()); if (log.isWarnEnabled()) { log.info("trying filestore " + source.getAbsolutePath()); } try { reader = ArchiveReaderFactory.get(source); } catch (IOException e) { throw new DigitalAssetStoreException( "Failed to get resource : " + e.getMessage()); } } record = reader.get(resource.getResourceOffset()); dest = File.createTempFile("wct", "tmp"); if (log.isDebugEnabled()) { log.debug("== Temp file: " + dest.getAbsolutePath()); } fos = new FileOutputStream(dest); if (record instanceof ARCRecord) { ((ARCRecord) record).skipHttpHeader(); } else { skipStatusLine(record); skipHeaders(record); } int bytesRead = 0; byte[] byteBuffer = new byte[BYTE_BUFF_SIZE]; while ((bytesRead = record.read(byteBuffer, 0, BYTE_BUFF_SIZE)) != -1) { fos.write(byteBuffer, 0, bytesRead); } if (fos != null) fos.close(); } catch (IOException e) { if (log.isErrorEnabled()) { log.error("Failed to get resource : " + e.getMessage(), e); } throw new DigitalAssetStoreException("Failed to get resource : " + e.getMessage()); } catch (RuntimeException ex) { if (log.isErrorEnabled()) { log.error("Failed to get resource : " + ex.getMessage(), ex); } throw new DigitalAssetStoreException("Failed to get resource : " + ex.getMessage()); } finally { try { if (fos != null) fos.close(); } catch (Exception ex) { if (log.isErrorEnabled()) { log.error("close fos failed " + ex.getMessage(), ex); } } try { if (record != null) record.close(); } catch (Exception ex) { if (log.isErrorEnabled()) { log.error("close record failed " + ex.getMessage(), ex); } } try { if (reader != null) reader.close(); } catch (Exception ex) { if (log.isErrorEnabled()) { log.error("close reader failed " + ex.getMessage(), ex); } } } return dest; }  void save(String targetInstanceName, String directory, File file); void save(String targetInstanceName, String directory, File[] files); void save(String targetInstanceName, File[] files); void save(String targetInstanceName, File file); @SuppressWarnings("finally") File getResource(String targetInstanceName, int harvestResultNumber,
                            HarvestResourceDTO resourcex); byte[] getSmallResource(String targetInstanceName,
                                   int harvestResultNumber, HarvestResourceDTO resourcex); Header[] getHeaders(String targetInstanceName,
                               int harvestResultNumber, HarvestResourceDTO resourcex); HarvestResultDTO copyAndPrune(String targetInstanceName,
                                         int orgHarvestResultNum, int newHarvestResultNum,
                                         List<String> urisToDelete, List<HarvestResourceDTO> hrsToImport); File getLogFile(String aJob, String aFileName); List<String> getLogFileNames(String aJob); LogFilePropertiesDTO[] getLogFileAttributes(String aJob); void purge(String[] targetInstanceNames); void purgeAbortedTargetInstances(String[] targetInstanceNames); void submitToArchive(String targetInstanceOid, String SIP,
                                Map xAttributes, int harvestNumber); CustomDepositFormResultDTO getCustomDepositFormDetails(
            CustomDepositFormCriteriaDTO criteria); void setArchive(Archive archive); void setBaseDir(String baseDir); void initiateIndexing(ArcHarvestResultDTO harvestResult); void initiateRemoveIndexes(ArcHarvestResultDTO harvestResult); Boolean checkIndexing(Long harvestResultOid); void setIndexer(Indexer indexer); void setDasFileMover(DasFileMover fileMover); void setWsEndPoint(WebServiceEndPoint wsEndPoint); void setPageImagePrefix(String pageImagePrefix); String getPageImagePrefix(); void setAqaReportPrefix(String aqaReportPrefix); String getAqaReportPrefix(); void setFileArchive(FileArchive fileArchive);  }