implement bencode base types
This commit is contained in:
parent
da9c812187
commit
7df116d02b
3 changed files with 52 additions and 8 deletions
18
src/main/java/com/mykola2312/retracker/bencode/BInteger.java
Normal file
18
src/main/java/com/mykola2312/retracker/bencode/BInteger.java
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package com.mykola2312.retracker.bencode;
|
||||
|
||||
public class BInteger extends BValue {
|
||||
private long value;
|
||||
|
||||
public BInteger(long value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override()
|
||||
public BType getType() {
|
||||
return BType.INTEGER;
|
||||
}
|
||||
|
||||
public long get() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
25
src/main/java/com/mykola2312/retracker/bencode/BString.java
Normal file
25
src/main/java/com/mykola2312/retracker/bencode/BString.java
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package com.mykola2312.retracker.bencode;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class BString extends BValue {
|
||||
private byte[] bytes;
|
||||
|
||||
public BString(byte[] bytes) {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
@Override()
|
||||
public BType getType() {
|
||||
return BType.STRING;
|
||||
}
|
||||
|
||||
public byte[] get() {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@Override()
|
||||
public String toString() {
|
||||
return new String(bytes, StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
|
|
@ -10,26 +10,27 @@ import java.util.Iterator;
|
|||
*/
|
||||
|
||||
abstract public class BValue implements Iterable<BValue> {
|
||||
private BType type;
|
||||
private BValue next = null;
|
||||
private BValue child = null;
|
||||
|
||||
protected BValue(BType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public BType getType() {
|
||||
return type;
|
||||
}
|
||||
abstract public BType getType();
|
||||
|
||||
public BValue getNext() {
|
||||
return next;
|
||||
}
|
||||
|
||||
public void setNext(BValue next) {
|
||||
this.next = next;
|
||||
}
|
||||
|
||||
public BValue getChild() {
|
||||
return child;
|
||||
}
|
||||
|
||||
public void setChild(BValue child) {
|
||||
this.child = child;
|
||||
}
|
||||
|
||||
public Iterator<BValue> iterator() {
|
||||
return new BValueIterator(child);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue