Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
QcmpCompressionLibrary
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BioinformaticDataCompression
QcmpCompressionLibrary
Commits
186990ac
Commit
186990ac
authored
4 years ago
by
Vojtech Moravec
Browse files
Options
Downloads
Patches
Plain Diff
Base prep for IQcmpFile abstraction.
parent
9ec82676
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/cz/it4i/qcmp/fileformat/IQcmpFile.java
+9
-0
9 additions, 0 deletions
src/main/java/cz/it4i/qcmp/fileformat/IQcmpFile.java
src/main/java/cz/it4i/qcmp/io/QcmpFileReader.java
+84
-0
84 additions, 0 deletions
src/main/java/cz/it4i/qcmp/io/QcmpFileReader.java
with
93 additions
and
0 deletions
src/main/java/cz/it4i/qcmp/fileformat/IQcmpFile.java
0 → 100644
+
9
−
0
View file @
186990ac
package
cz.it4i.qcmp.fileformat
;
import
java.io.IOException
;
public
interface
IQcmpFile
{
IFileHeader
getHeader
();
void
convertToNewerVersion
(
final
boolean
inPlace
,
final
String
inputPath
,
final
String
outputPath
)
throws
IOException
;
}
This diff is collapsed.
Click to expand it.
src/main/java/cz/it4i/qcmp/io/QcmpFileReader.java
0 → 100644
+
84
−
0
View file @
186990ac
package
cz.it4i.qcmp.io
;
import
cz.it4i.qcmp.fileformat.IFileHeader
;
import
cz.it4i.qcmp.fileformat.IQcmpFile
;
import
cz.it4i.qcmp.fileformat.QCMPFileHeaderV1
;
import
cz.it4i.qcmp.fileformat.QCMPFileHeaderV2
;
import
java.io.DataInputStream
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
public
class
QcmpFileReader
{
private
static
final
int
QCMP_HEADER_MAGIC_VALUE_SIZE
=
8
;
/**
* Read cache file from file.
*
* @param path File path.
* @return Cache file or null if reading fails.
*/
public
static
IQcmpFile
readCacheFile
(
final
String
path
)
throws
IOException
{
try
(
final
FileInputStream
fis
=
new
FileInputStream
(
path
))
{
return
readQcmpFile
(
fis
);
}
}
/**
* Make DataInputStream from InputStream.
*
* @param inputStream Some input stream.
* @return DataInputStream.
*/
private
static
DataInputStream
asDataInputStream
(
final
InputStream
inputStream
)
{
if
(
inputStream
instanceof
DataInputStream
)
{
return
(
DataInputStream
)
inputStream
;
}
else
{
return
new
DataInputStream
(
inputStream
);
}
}
/**
* Create correct Qcmp header version by analyzing the magic value.
*
* @param magicValue Magic value of the qcmp file.
* @return Correct version of QCMP header.
* @throws IOException when the magic value is unknown.
*/
private
static
IFileHeader
getCorrectQcmpHeader
(
final
String
magicValue
)
throws
IOException
{
switch
(
magicValue
)
{
case
QCMPFileHeaderV1
.
MAGIC_VALUE
:
return
new
QCMPFileHeaderV1
();
case
QCMPFileHeaderV2
.
MAGIC_VALUE
:
return
new
QCMPFileHeaderV2
();
default
:
throw
new
IOException
(
"Invalid QCMP file. Unknown QCMP magic value: "
+
magicValue
);
}
}
/**
* Read cache file by DataInputStream.
*
* @param inputStream Input stream.
* @return Cache file or null, if exception occurs.
*/
private
static
IQcmpFile
readQcmpFile
(
final
InputStream
inputStream
)
throws
IOException
{
final
DataInputStream
dis
=
asDataInputStream
(
inputStream
);
final
byte
[]
magicValueBuffer
=
new
byte
[
QCMP_HEADER_MAGIC_VALUE_SIZE
];
RawDataIO
.
readFullBuffer
(
dis
,
magicValueBuffer
);
final
String
magicValue
=
new
String
(
magicValueBuffer
);
final
IFileHeader
header
=
getCorrectQcmpHeader
(
magicValue
);
header
.
readFromStream
(
dis
);
assert
((
header
.
getHeaderVersion
()
==
1
&&
header
instanceof
QCMPFileHeaderV1
)
||
header
.
getHeaderVersion
()
==
2
&&
header
instanceof
QCMPFileHeaderV2
);
// TODO(Moravec): Create the IQcmpFile impl. Think about it!
return
null
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment