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
8aeb9e04
Commit
8aeb9e04
authored
5 years ago
by
Vojtech Moravec
Browse files
Options
Downloads
Patches
Plain Diff
OutBitStream prototype.
parent
b2c7bb0f
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/DataCompressor.java
+2
-2
2 additions, 2 deletions
src/main/java/DataCompressor.java
src/main/java/compression/io/OutBitStream.java
+96
-0
96 additions, 0 deletions
src/main/java/compression/io/OutBitStream.java
with
98 additions
and
2 deletions
src/main/java/DataCompressor.java
+
2
−
2
View file @
8aeb9e04
import
cli.CliConstants
;
import
cli.ParsedCliOptions
;
import
compression.io.Out
Memory
BitStream
;
import
compression.io.OutBitStream
;
import
org.apache.commons.cli.*
;
import
org.jetbrains.annotations.NotNull
;
...
...
@@ -11,7 +11,7 @@ public class DataCompressor {
public
static
void
main
(
String
[]
args
)
throws
IOException
{
Out
Memory
BitStream
bitStream
=
new
Out
Memory
BitStream
(
null
,
3
,
64
);
OutBitStream
bitStream
=
new
OutBitStream
(
null
,
3
,
64
);
bitStream
.
write
(
0
);
bitStream
.
write
(
1
);
bitStream
.
write
(
2
);
...
...
This diff is collapsed.
Click to expand it.
src/main/java/compression/io/OutBitStream.java
0 → 100644
+
96
−
0
View file @
8aeb9e04
package
compression.io
;
import
java.io.IOException
;
import
java.io.OutputStream
;
public
class
OutBitStream
{
private
OutputStream
outStream
;
private
byte
[]
buffer
;
private
int
bufferPosition
;
private
byte
bitBuffer
=
0x00
;
private
byte
bitBufferSize
=
0x00
;
private
final
int
bitsPerValue
;
public
OutBitStream
(
OutputStream
outputStream
,
final
int
bitsPerValue
,
final
int
bufferSize
)
{
this
.
bitsPerValue
=
bitsPerValue
;
buffer
=
new
byte
[
bufferSize
];
bufferPosition
=
0
;
bitBuffer
=
0
;
bitBufferSize
=
0
;
outStream
=
outputStream
;
}
/**
* Flush the memory buffer to the underlying stream.
*/
private
void
flushBuffer
()
throws
IOException
{
outStream
.
write
(
buffer
,
0
,
bufferPosition
);
bufferPosition
=
0
;
}
/**
* Flush the bit buffer into the memory buffer.
*/
private
void
flushBitBuffer
()
throws
IOException
{
if
(
bitBufferSize
>
0
)
{
buffer
[
bufferPosition
++]
=
bitBuffer
;
bitBuffer
=
0
;
bitBufferSize
=
0
;
if
(
bufferPosition
==
buffer
.
length
)
{
flushBuffer
();
}
}
}
public
void
forceFlush
()
throws
IOException
{
flushBitBuffer
();
flushBuffer
();
}
/**
* Write bit to the memory bit buffer.
*
* @param bit True for 1
*/
private
void
writeBit
(
final
int
bit
)
throws
IOException
{
// ++bitBufferSize;
if
(
bit
>
0
)
{
// bitBuffer |= (1 << (8 - bitBufferSize));
bitBuffer
|=
(
1
<<
bitBufferSize
);
}
++
bitBufferSize
;
if
(
bitBufferSize
==
8
)
{
flushBitBuffer
();
}
}
// public void write(final byte value) {
//
// }
//
// public void write(final short value) {
//
// }
public
void
write
(
final
int
value
)
throws
IOException
{
int
bit
;
for
(
int
shift
=
0
;
shift
<
bitsPerValue
;
shift
++)
{
bit
=
(
value
&
(
1
<<
shift
));
//bit = (value & (1 << (31 - shift)));
writeBit
(
bit
);
}
}
}
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