-
Notifications
You must be signed in to change notification settings - Fork 1
/
FsScanner.java
163 lines (146 loc) · 4.68 KB
/
FsScanner.java
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
(c) Copyright 2004 Gary Dusbabek [email protected]
ALL RIGHTS RESERVED.
By using this software, you acknowlege and agree that:
1. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND
FITNESS FOR A PARTICULAR PURPOSE.
2. This product may be freely copied and distributed in source or binary form
given that the license (this file) and any copyright declarations remain in
tact.
The End
*/
package com.dusbabek.lib.id3;
import java.io.*;
/**
* Debugging class used to scan a directory and evaulate id3 tags.
*/
public class FsScanner
{
private static File DEST_DIR = System.getProperty("dest") == null ? null : new File(System.getProperty("dest"));
private static long dumpCount = 0;
private static long dumpTime = 0;
private File f;
private Reader r = new Reader();
private int noTag = 0;
private int badVersion = 0;
private int otherErr = 0;
private int ok = 0;
public FsScanner(File f)
{
this.f = f;
}
public void scan()
{
try
{
scan(f);
if (DEST_DIR != null)
{
System.out.println("dumped " + dumpCount + " in " + dumpTime);
}
}
catch (IOException ex)
{
ex.printStackTrace();
}
System.out.println("ok="+ok+" noTag="+noTag+" badVersion="+badVersion+" other="+otherErr);
}
private void scan(File f)
throws IOException
{
if (f.isDirectory())
{
File[] list = f.listFiles();
for (int i = 0; i < list.length; i++)
{
if (list[i].isDirectory())
scan(list[i]);
else if (list[i].getName().toLowerCase().endsWith(".mp3") && !list[i].getName().startsWith("."))
scan(list[i]);
}
}
else
{
FileInputStream in = null;
try
{
in = new FileInputStream(f);
Tag id3 = null;
try
{
r.read(in);
System.out.println("OK : " + f.getAbsolutePath());
}
catch (CorruptTagException ex)
{
System.err.println("CORRUPT: " + f.getAbsolutePath());
System.err.println(" " + ex.getMessage());
return;
}
catch (InvalidVersionException ex)
{
System.err.println("BAD_VERSION: " + f.getAbsolutePath());
return;
}
catch (NotATagException ex)
{
System.err.println("NO_TAG: " + f.getAbsolutePath());
return;
}
if (DEST_DIR != null)
{
long start = System.currentTimeMillis();
File of = new File(DEST_DIR,"test-" + f.getName());
FileOutputStream out = new FileOutputStream(of,false);
id3.write(out);
in.close();
in = new FileInputStream(f);
long size = f.length();
long passed = id3.originalTagLength();
in.skip(passed);
while (passed < size)
{
byte[] buf = new byte[in.available()];
int read = in.read(buf);
out.write(buf);
passed += read;
}
out.flush();
out.close();
long end = System.currentTimeMillis();
dumpCount++;
dumpTime += (end-start);
}
ok++;
}
catch (NotATagException ex)
{
System.err.println("no tag " + f.getName());
noTag++;
}
catch (InvalidVersionException ex)
{
badVersion++;
}
catch (IOException ex)
{
System.err.print(f.getName() + " " );
ex.printStackTrace();
otherErr++;
}
finally
{
try { in.close(); } catch (Exception ex) { }
}
}
}
public static void main(String args[])
{
String source = System.getProperty("source");
String dest = System.getProperty("dest");
File f = new File(source);
FsScanner fs = new FsScanner(f);
fs.scan();
}
}