-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Defines V2 archive index properties - Implements parsers for both archive index versions - Uses the parsers instead of direct properties access - Adds new tests Resolves #248 {minor} Signed-off-by: Esta Nagy <[email protected]>
- Loading branch information
Showing
10 changed files
with
415 additions
and
55 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
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
56 changes: 56 additions & 0 deletions
56
file-barj-stream-io/src/main/java/com/github/nagyesta/filebarj/io/stream/IndexVersion.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,56 @@ | ||
package com.github.nagyesta.filebarj.io.stream; | ||
|
||
import com.github.nagyesta.filebarj.io.stream.index.ArchiveIndexV1; | ||
import com.github.nagyesta.filebarj.io.stream.index.ArchiveIndexV2; | ||
import lombok.Getter; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Properties; | ||
|
||
/** | ||
* The version of the File Barj index specification. | ||
*/ | ||
@Getter | ||
public enum IndexVersion { | ||
/** | ||
* The initial version of the File Barj index specification. | ||
*/ | ||
V1("1") { | ||
@Override | ||
ReadOnlyArchiveIndex createIndex(@NotNull final Properties properties) { | ||
return new ArchiveIndexV1(properties); | ||
} | ||
}, | ||
/** | ||
* The 2nd version of the File Barj index specification. | ||
*/ | ||
V2("2") { | ||
@Override | ||
ReadOnlyArchiveIndex createIndex(@NotNull final Properties properties) { | ||
return new ArchiveIndexV2(properties); | ||
} | ||
}; | ||
|
||
private final String version; | ||
|
||
IndexVersion(final String version) { | ||
this.version = version; | ||
} | ||
|
||
public static IndexVersion forVersionString(final String version) { | ||
for (final var indexVersion : values()) { | ||
if (indexVersion.version.equals(version)) { | ||
return indexVersion; | ||
} | ||
} | ||
return V1; | ||
} | ||
|
||
/** | ||
* Instantiates a read-only archive index from the given properties. | ||
* | ||
* @param properties the properties | ||
* @return the read-only archive index | ||
*/ | ||
abstract ReadOnlyArchiveIndex createIndex(@NotNull Properties properties); | ||
} |
26 changes: 26 additions & 0 deletions
26
...-stream-io/src/main/java/com/github/nagyesta/filebarj/io/stream/ReadOnlyArchiveIndex.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,26 @@ | ||
package com.github.nagyesta.filebarj.io.stream; | ||
|
||
import com.github.nagyesta.filebarj.io.stream.internal.model.BarjCargoEntityIndex; | ||
|
||
/** | ||
* A read-only representation of an archive index file. | ||
*/ | ||
public interface ReadOnlyArchiveIndex { | ||
|
||
/** | ||
* The name of the property that contains the version of the index specification. | ||
*/ | ||
String INDEX_VERSION = "version"; | ||
|
||
int getNumberOfChunks(); | ||
|
||
long getMaxChunkSizeInBytes(); | ||
|
||
long getLastChunkSizeInBytes(); | ||
|
||
long getTotalSize(); | ||
|
||
long getTotalEntities(); | ||
|
||
BarjCargoEntityIndex entity(String prefix); | ||
} |
41 changes: 41 additions & 0 deletions
41
...-stream-io/src/main/java/com/github/nagyesta/filebarj/io/stream/index/ArchiveIndexV1.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,41 @@ | ||
package com.github.nagyesta.filebarj.io.stream.index; | ||
|
||
import com.github.nagyesta.filebarj.io.stream.IndexVersion; | ||
import com.github.nagyesta.filebarj.io.stream.ReadOnlyArchiveIndex; | ||
import com.github.nagyesta.filebarj.io.stream.internal.model.BarjCargoEntityIndex; | ||
import lombok.Getter; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Properties; | ||
|
||
@Getter | ||
public class ArchiveIndexV1 implements ReadOnlyArchiveIndex { | ||
|
||
private static final String LAST_ENTITY_INDEX_PROPERTY = "last.entity.index"; | ||
private static final String LAST_CHUNK_INDEX_PROPERTY = "last.cnunk.index"; | ||
private static final String LAST_CHUNK_SIZE_PROPERTY = "last.cnunk.size"; | ||
private static final String MAX_CHUNK_SIZE_PROPERTY = "max.cnunk.size"; | ||
private static final String TOTAL_SIZE_PROPERTY = "total.size"; | ||
private final Properties properties; | ||
private final IndexVersion indexVersion; | ||
private final long totalEntities; | ||
private final int numberOfChunks; | ||
private final long maxChunkSizeInBytes; | ||
private final long lastChunkSizeInBytes; | ||
private final long totalSize; | ||
|
||
public ArchiveIndexV1(@NotNull final Properties properties) { | ||
this.properties = properties; | ||
this.indexVersion = IndexVersion.forVersionString(properties.getProperty(INDEX_VERSION)); | ||
this.totalEntities = Long.parseLong(properties.getProperty(LAST_ENTITY_INDEX_PROPERTY)); | ||
this.numberOfChunks = Integer.parseInt(properties.getProperty(LAST_CHUNK_INDEX_PROPERTY)); | ||
this.maxChunkSizeInBytes = Long.parseLong(properties.getProperty(MAX_CHUNK_SIZE_PROPERTY)); | ||
this.lastChunkSizeInBytes = Long.parseLong(properties.getProperty(LAST_CHUNK_SIZE_PROPERTY)); | ||
this.totalSize = Long.parseLong(properties.getProperty(TOTAL_SIZE_PROPERTY)); | ||
} | ||
|
||
@Override | ||
public BarjCargoEntityIndex entity(@NotNull final String prefix) { | ||
return BarjCargoEntityIndex.fromProperties(properties, prefix); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...-stream-io/src/main/java/com/github/nagyesta/filebarj/io/stream/index/ArchiveIndexV2.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,70 @@ | ||
package com.github.nagyesta.filebarj.io.stream.index; | ||
|
||
import com.github.nagyesta.filebarj.io.stream.IndexVersion; | ||
import com.github.nagyesta.filebarj.io.stream.ReadOnlyArchiveIndex; | ||
import com.github.nagyesta.filebarj.io.stream.internal.model.BarjCargoEntityIndex; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Properties; | ||
|
||
import static com.github.nagyesta.filebarj.io.stream.BarjCargoUtil.COLON; | ||
import static com.github.nagyesta.filebarj.io.stream.BarjCargoUtil.LINE_BREAK; | ||
|
||
@Getter | ||
public class ArchiveIndexV2 implements ReadOnlyArchiveIndex { | ||
|
||
private static final String LAST_ENTITY_INDEX_PROPERTY = "last.entity.index"; | ||
private static final String LAST_CHUNK_INDEX_PROPERTY = "last.chunk.index"; | ||
private static final String LAST_CHUNK_SIZE_PROPERTY = "last.chunk.size"; | ||
private static final String MAX_CHUNK_SIZE_PROPERTY = "max.chunk.size"; | ||
private static final String TOTAL_SIZE_PROPERTY = "total.size"; | ||
private final Properties properties; | ||
private final IndexVersion indexVersion; | ||
private final long totalEntities; | ||
private final int numberOfChunks; | ||
private final long maxChunkSizeInBytes; | ||
private final long lastChunkSizeInBytes; | ||
private final long totalSize; | ||
|
||
public ArchiveIndexV2(@NotNull final Properties properties) { | ||
this.properties = properties; | ||
this.indexVersion = IndexVersion.forVersionString(properties.getProperty(INDEX_VERSION)); | ||
this.totalEntities = Long.parseLong(properties.getProperty(LAST_ENTITY_INDEX_PROPERTY)); | ||
this.numberOfChunks = Integer.parseInt(properties.getProperty(LAST_CHUNK_INDEX_PROPERTY)); | ||
this.maxChunkSizeInBytes = Long.parseLong(properties.getProperty(MAX_CHUNK_SIZE_PROPERTY)); | ||
this.lastChunkSizeInBytes = Long.parseLong(properties.getProperty(LAST_CHUNK_SIZE_PROPERTY)); | ||
this.totalSize = Long.parseLong(properties.getProperty(TOTAL_SIZE_PROPERTY)); | ||
} | ||
|
||
@Builder | ||
public ArchiveIndexV2( | ||
final long totalSize, | ||
final long lastChunkSizeInBytes, | ||
final long maxChunkSizeInBytes, | ||
final int numberOfChunks, | ||
final long totalEntities) { | ||
this.indexVersion = IndexVersion.V2; | ||
this.properties = null; | ||
this.totalSize = totalSize; | ||
this.lastChunkSizeInBytes = lastChunkSizeInBytes; | ||
this.maxChunkSizeInBytes = maxChunkSizeInBytes; | ||
this.numberOfChunks = numberOfChunks; | ||
this.totalEntities = totalEntities; | ||
} | ||
|
||
@Override | ||
public BarjCargoEntityIndex entity(@NotNull final String prefix) { | ||
return BarjCargoEntityIndex.fromProperties(properties, prefix); | ||
} | ||
|
||
public String footerAsString() { | ||
return LAST_CHUNK_INDEX_PROPERTY + COLON + numberOfChunks + LINE_BREAK | ||
+ LAST_CHUNK_SIZE_PROPERTY + COLON + lastChunkSizeInBytes + LINE_BREAK | ||
+ MAX_CHUNK_SIZE_PROPERTY + COLON + maxChunkSizeInBytes + LINE_BREAK | ||
+ LAST_ENTITY_INDEX_PROPERTY + COLON + totalEntities + LINE_BREAK | ||
+ TOTAL_SIZE_PROPERTY + COLON + totalSize + LINE_BREAK | ||
+ INDEX_VERSION + COLON + indexVersion.getVersion() + LINE_BREAK; | ||
} | ||
} |
Oops, something went wrong.