@@ -23,7 +23,22 @@ class AASPChunkStorageFS implements AASPChunkStorage {
2323 public AASPChunk getChunk (CharSequence uriTarget , int era ) throws IOException {
2424 return new AASPChunkFS (this , (String ) uriTarget , era );
2525 }
26-
26+
27+ @ Override
28+ public boolean existsChunk (CharSequence uri , int era ) throws IOException {
29+ String fullContentFileName = this .getChunkContentFilename (era , uri );
30+
31+ return (new File (fullContentFileName ).exists ());
32+ }
33+
34+ String getChunkContentFilename (int era , CharSequence uri ) {
35+ return this .getChunkFileTrunkname (era , uri .toString ()) + "." + DATA_EXTENSION ;
36+ }
37+
38+ String getChunkFileTrunkname (int era , String uri ) {
39+ return this .getPath (era ) + "/" + this .url2FileName (uri );
40+ }
41+
2742 String url2FileName (String url ) {
2843 // escape:
2944 /*
@@ -52,8 +67,8 @@ String url2FileName(String url) {
5267 * @return full name (path/name) of that given url and target. Directories
5368 * are created if necessary.
5469 */
55- String getFullFileName (int era , String targetUrl ) {
56- String eraFolderString = this .getRootPath () + "/" + Integer . toString (era );
70+ String setupChunkFolder (int era , String targetUrl ) {
71+ String eraFolderString = this .getPath (era );
5772 File eraFolder = new File (eraFolderString );
5873 if (!eraFolder .exists ()) {
5974 eraFolder .mkdirs ();
@@ -62,15 +77,15 @@ String getFullFileName(int era, String targetUrl) {
6277 String fileName = eraFolderString + "/" + this .url2FileName (targetUrl );
6378 return fileName ;
6479 }
65-
80+
6681 /**
6782 *
6883 * @param era
6984 * @return full name (path/name) of that given url and target. Directories
7085 * are expected to be existent
7186 */
72- String getFullFileNameByChunkName (int era , String contentName ) {
73- return this .getPath (era ) + "/" + contentName ;
87+ String getFileNameByUri (int era , String uri ) {
88+ return this .getPath (era ) + "/" + uri ;
7489 }
7590
7691 private String getPath (int era ) {
@@ -99,7 +114,7 @@ public boolean accept(File dir, String fileName) {
99114 int index = name .lastIndexOf ('.' );
100115 if (index != -1 ) {
101116 String chunkName = name .substring (0 , index );
102- String fName = this .getFullFileNameByChunkName (era , chunkName );
117+ String fName = this .getFileNameByUri (era , chunkName );
103118 chunkList .add (new AASPChunkFS (this , fName ));
104119 }
105120 }
@@ -117,13 +132,18 @@ public void dropChunks(int era) throws IOException {
117132
118133 }
119134
120- String getRootPath () {
121- return this .rootDirectory ;
122- }
123-
124135 @ Override
125- public AASPChunkCache getAASPChunkCache (CharSequence uri , int fromEra ,
126- int toEra ) throws IOException {
127- return new AASPInMemoChunkCache (this , uri , fromEra , toEra );
136+ public AASPChunkCache getAASPChunkCache (CharSequence uri , int toEra ) throws IOException {
137+ // go back 1000 eras
138+ int fromEra = toEra ;
139+ for (int i = 0 ; i < 1000 ; i ++) {
140+ fromEra = AASPEngine .previousEra (fromEra );
141+ }
142+
143+ return new AASPInMemoChunkCache (this ,
144+ uri ,
145+ fromEra , // set starting era
146+ toEra // anything before
147+ );
128148 }
129149}
0 commit comments