Skip to content

Commit

Permalink
Code style
Browse files Browse the repository at this point in the history
  • Loading branch information
njovic committed Aug 31, 2024
1 parent 9e40123 commit 53855ba
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 108 deletions.
20 changes: 12 additions & 8 deletions Source/com/drew/metadata/mkv/AudioDirectory.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@

import static com.drew.metadata.mkv.ElementIDs.*;

public class AudioDirectory extends Directory {
public class AudioDirectory extends Directory
{
private static final HashMap<Integer, String> _tagNameMap = new HashMap<>();

public AudioDirectory(){
this.setDescriptor(new TagDescriptor<Directory>(this));
}
static {

static
{
_tagNameMap.put(TRACK_NUMBER, "Track number");
_tagNameMap.put(TRACK_UID, "Track UID");
_tagNameMap.put(TRACK_TYPE, "Track type");
Expand All @@ -26,16 +24,22 @@ public AudioDirectory(){
_tagNameMap.put(CHANNELS, "Channels");
_tagNameMap.put(SAMPLING_FREQUENCY, "Sampling frequency");
_tagNameMap.put(BIT_DEPTH, "Bit depth");
}

public AudioDirectory()
{
this.setDescriptor(new TagDescriptor<Directory>(this));
}

@Override
public String getName() {
public String getName()
{
return "Audio";
}

@Override
protected HashMap<Integer, String> getTagNameMap() {
protected HashMap<Integer, String> getTagNameMap()
{
return _tagNameMap;
}
}
50 changes: 32 additions & 18 deletions Source/com/drew/metadata/mkv/DataParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,65 +4,79 @@

import java.io.IOException;

public class DataParser {
private static final long[] VSINT_SUBTR = { 0x3F, 0x1FFF, 0x0FFFFF, 0x07FFFFFF,
0x03FFFFFFFFL, 0x01FFFFFFFFFFL,
0x00FFFFFFFFFFFFL, 0x007FFFFFFFFFFFFFL };
public class DataParser
{
private static final long[] VSINT_SUBTR = {0x3F, 0x1FFF, 0x0FFFFF, 0x07FFFFFF, 0x03FFFFFFFFL, 0x01FFFFFFFFFFL, 0x00FFFFFFFFFFFFL, 0x007FFFFFFFFFFFFFL};

static long doDecodeInteger(final SequentialReader reader, boolean signed) throws IOException {
static long doDecodeInteger(final SequentialReader reader, boolean signed) throws IOException
{
byte firstByte = reader.getBytes(1)[0];
int position = 7;
for (; position >= 0; position--) {
if ((firstByte & (1 << position)) != 0) {
for (; position >= 0; position--)
{
if ((firstByte & (1 << position)) != 0)
{
break;
}
}
int length = 7 - position;
byte[] values = reader.getBytes(length);
long result = (firstByte & ((1L << position) - 1)) << (length * 8);
for (int i = 1; i <= length; i++) {
for (int i = 1; i <= length; i++)
{
result |= ((long) (values[i - 1] & 0xFF) << ((length - i) * 8));
}
return signed ? result - VSINT_SUBTR[length] : result;
}

static long decodeInteger(final SequentialReader reader) throws IOException {
static long decodeInteger(final SequentialReader reader) throws IOException
{
return doDecodeInteger(reader, false);
}

static long decodeSignedInteger(final SequentialReader reader) throws IOException {
static long decodeSignedInteger(final SequentialReader reader) throws IOException
{
return doDecodeInteger(reader, true);
}

static int getElementId(final SequentialReader reader) throws IOException {
static int getElementId(final SequentialReader reader) throws IOException
{
byte firstByte = reader.getBytes(1)[0];
int position = 7;
for (; position >= 0; position--) {
if ((firstByte & (1 << position)) != 0) {
for (; position >= 0; position--)
{
if ((firstByte & (1 << position)) != 0)
{
break;
}
}
int length = 7 - position;
byte[] values = reader.getBytes(length);
int result = ((int) (firstByte & 0xFF)) << (length * 8);
for (int i = 1; i <= length; i++) {
for (int i = 1; i <= length; i++)
{
result |= (((int) values[i - 1] & 0xFF) << ((length - i) * 8));
}
return result;
}

static long getLong(final SequentialReader reader, long size) throws IOException {
static long getLong(final SequentialReader reader, long size) throws IOException
{
long result = 0L;
for (long i = size - 1; i >= 0; i--){
for (long i = size - 1; i >= 0; i--)
{
result |= (long) (reader.getByte() & 0xFF) << (i * 8);
}
return result;
}

static byte[] getByteArray(final SequentialReader reader, long size) throws IOException {
static byte[] getByteArray(final SequentialReader reader, long size) throws IOException
{
return reader.getBytes((int) size);
}
static String getString(final SequentialReader reader, long size) throws IOException{

static String getString(final SequentialReader reader, long size) throws IOException
{
return reader.getString((int) size);
}
}
17 changes: 12 additions & 5 deletions Source/com/drew/metadata/mkv/EbmlDirectory.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
import com.drew.metadata.TagDescriptor;

import java.util.HashMap;

import static com.drew.metadata.mkv.ElementIDs.*;

public class EbmlDirectory extends Directory {
public class EbmlDirectory extends Directory
{

private static final HashMap<Integer, String> _tagNameMap = new HashMap<>();
static {

static
{
_tagNameMap.put(EBML_VERSION, "Version");
_tagNameMap.put(EBML_READ_VERSION, "Read version");
_tagNameMap.put(EBML_MAX_ID_LENGTH, "Maximum ID length");
Expand All @@ -19,17 +23,20 @@ public class EbmlDirectory extends Directory {
_tagNameMap.put(DOCTYPE_READ_VERSION, "Doctype read version");
}

public EbmlDirectory() {
public EbmlDirectory()
{
this.setDescriptor(new TagDescriptor<Directory>(this));
}

@Override
public String getName() {
public String getName()
{
return "EBML";
}

@Override
protected HashMap<Integer, String> getTagNameMap() {
protected HashMap<Integer, String> getTagNameMap()
{
return _tagNameMap;
}
}
51 changes: 31 additions & 20 deletions Source/com/drew/metadata/mkv/EbmlElement.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,50 @@
package com.drew.metadata.mkv;

public class EbmlElement {
private final String name;
private final Type type;
private final DirectoryType directory;
public class EbmlElement
{
private final String _name;
private final Type _type;
private final DirectoryType _directory;

public String toString(){
return name;
public EbmlElement(String _name, Type type)
{
this(_name, type, DirectoryType.UNKNOWN);
}
public String getName() {
return name;

public EbmlElement(String name, Type type, DirectoryType directory)
{
_name = name;
_type = type;
_directory = directory;
}

public Type getType() {
return type;
public String toString()
{
return _name;
}

public EbmlElement(String name, Type type) {
this(name, type, DirectoryType.UNKNOWN);
public String get_name()
{
return _name;
}
public EbmlElement(String name, Type type, DirectoryType directory) {
this.name = name;
this.type = type;
this.directory = directory;

public Type get_type()
{
return _type;
}

public DirectoryType getDirectory() {
return directory;
public DirectoryType getDirectory()
{
return _directory;
}

public enum Type{
public enum Type
{
MASTER, STRING, INTEGER, SIGNED_INTEGER, UTF8, BINARY, VOID, UNKNOWN, FLOAT
}

public enum DirectoryType{
public enum DirectoryType
{
EBML, SEGMENT, VIDEO, AUDIO, UNKNOWN
}
}
3 changes: 2 additions & 1 deletion Source/com/drew/metadata/mkv/ElementIDs.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.drew.metadata.mkv;

public class ElementIDs {
public class ElementIDs
{

static final int EBML_HEADER_ELEMENT = 0x1A45DFA3;
static final int EBML_VERSION = 0x4286;
Expand Down
Loading

0 comments on commit 53855ba

Please sign in to comment.