-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathID3v2PopmFrameData.java
More file actions
111 lines (91 loc) · 2.54 KB
/
Copy pathID3v2PopmFrameData.java
File metadata and controls
111 lines (91 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package Mp3File;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
public class ID3v2PopmFrameData extends AbstractID3v2FrameData {
protected static final String WMP9_ADDRESS = "Windows Media Player 9 Series";
protected String address = "";
protected int rating = -1;
private static final Map<Byte, Integer> byteToRating = new HashMap<>(5);
private static final byte[] wmp9encodedRatings = {(byte) 0x00, (byte) 0x01, (byte) 0x40, (byte) 0x80, (byte) 0xC4,
(byte) 0xFF};
static {
for (int i = 0; i < 6; i++) {
byteToRating.put(wmp9encodedRatings[i], i);
}
}
public ID3v2PopmFrameData(boolean unsynchronisation, byte[] bytes) throws InvalidDataException {
super(unsynchronisation);
synchroniseAndUnpackFrameData(bytes);
}
public ID3v2PopmFrameData(boolean unsynchronisation, int rating) {
super(unsynchronisation);
this.address = WMP9_ADDRESS;
this.rating = rating;
}
@Override
protected void unpackFrameData(byte[] bytes) throws InvalidDataException {
try {
address = BufferTools.byteBufferToString(bytes, 0, bytes.length - 2);
} catch (UnsupportedEncodingException e) {
address = "";
}
final byte ratingByte = bytes[bytes.length - 1];
if (byteToRating.containsKey(ratingByte)) {
rating = byteToRating.get(ratingByte);
} else {
rating = -1;
}
}
@Override
protected byte[] packFrameData() {
byte[] bytes = address.getBytes();
bytes = Arrays.copyOf(bytes, address.length() + 2);
bytes[bytes.length - 2] = 0;
bytes[bytes.length - 1] = wmp9encodedRatings[rating];
return bytes;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public int getRating() {
return rating;
}
public void setRating(int rating) {
this.rating = rating;
}
@Override
protected int getLength() {
return address.length() + 2;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((address == null) ? 0 : address.hashCode());
result = prime * result + rating;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
ID3v2PopmFrameData other = (ID3v2PopmFrameData) obj;
if (address == null) {
if (other.address != null)
return false;
} else if (!address.equals(other.address))
return false;
if (rating != other.rating)
return false;
return true;
}
}