This repository has been archived by the owner on Jan 3, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
84 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ FedoraRepository/ | |
indexes/ | ||
ObjectStore/ | ||
*/.cache | ||
fcrepo-jms-indexer-core/data/** | ||
.cache | ||
.DS_Store | ||
*~ | ||
|
62 changes: 62 additions & 0 deletions
62
fcrepo-jms-indexer-core/src/main/java/org/fcrepo/indexer/CachingRetriever.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* Copyright 2013 DuraSpace, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/** | ||
* | ||
*/ | ||
package org.fcrepo.indexer; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import org.apache.http.HttpException; | ||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.ClientProtocolException; | ||
|
||
|
||
/** | ||
* @author ajs6f | ||
* @date Dec 7, 2013 | ||
*/ | ||
public abstract class CachingRetriever implements IndexableContentRetriever { | ||
|
||
private Boolean cached = false; | ||
|
||
private byte[] cache; | ||
|
||
/* (non-Javadoc) | ||
* @see java.util.concurrent.Callable#call() | ||
*/ | ||
@Override | ||
public InputStream call() throws ClientProtocolException, IOException, | ||
CannotTransformToNamedFieldsException, HttpException { | ||
if (cached) { | ||
return new ByteArrayInputStream(cache); | ||
} | ||
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { | ||
retrieveHttpResponse().getEntity().writeTo(out); | ||
cache = out.toByteArray(); | ||
} | ||
cached = true; | ||
return new ByteArrayInputStream(cache); | ||
} | ||
|
||
protected abstract HttpResponse retrieveHttpResponse() | ||
throws CannotTransformToNamedFieldsException, | ||
ClientProtocolException, IOException, HttpException; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters