Skip to content

Commit bd39c5d

Browse files
committed
Merge branch 'release-0.1'
2 parents afdd146 + 2c6a5b7 commit bd39c5d

File tree

6 files changed

+97
-27
lines changed

6 files changed

+97
-27
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ Yatour M-06 folderer.
44
1. java 7.
55

66
##Usage:
7-
1. Put your mp3 files in one folder, for example D:\music
8-
2. Insert your flash and formate this in FAT32 file system.
7+
1. Place your mp3 files in folder, for example: D:\music
8+
2. Connect your yatour device (flash) to computer and format it in FAT32 file system.
99
3. Run yatour-folderer from command line:
1010

11-
**java -jar yatour-folderer.jar D:\music F:\**
11+
**java -jar yatour-folderer.jar -in D:\music -out F:\**
1212

13-
where **F:\** - this is path to your flash.
13+
where **F:\** - this is path to your yatour device (flash).
1414

1515
Enjoy!

pom.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>ru.kindteam</groupId>
55
<artifactId>yatour-folderer</artifactId>
66
<packaging>jar</packaging>
7-
<version>1.0-SNAPSHOT</version>
7+
<version>0.1</version>
88
<name>yatour-folderer</name>
99
<url>http://maven.apache.org</url>
1010

@@ -24,6 +24,13 @@
2424
<artifactId>commons-io</artifactId>
2525
<version>1.3.2</version>
2626
</dependency>
27+
28+
<dependency>
29+
<groupId>commons-cli</groupId>
30+
<artifactId>commons-cli</artifactId>
31+
<version>1.2</version>
32+
</dependency>
33+
2734

2835
</dependencies>
2936
<build>

src/main/java/ru/kindteam/MusicFileCopier.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
/**
2-
*
3-
*/
41
package ru.kindteam;
52

63
import java.io.IOException;
@@ -23,12 +20,22 @@ public class MusicFileCopier
2320
private int folderCounter = 0;
2421
private int fileCounter = MAX_COUNT_IN_FOLDER;
2522

26-
public MusicFileCopier(Path source, Path target) throws IOException
23+
private MusicFileCopier(MusicFileDataSource files, Path target)
2724
{
28-
files = MusicFileDataSource.create(source);
25+
this.files = files;
2926
this.target = target;
3027
}
3128

29+
public static MusicFileCopier create(Path source, Path target) throws IOException
30+
{
31+
return new MusicFileCopier(MusicFileDataSource.create(source), target);
32+
}
33+
34+
/**
35+
* Выполнение копирования файлов с заданными параметрами.
36+
*
37+
* @throws IOException
38+
*/
3239
public void copyFiles() throws IOException
3340
{
3441
for (Path source : files)

src/main/java/ru/kindteam/MusicFileDataSource.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
import java.util.TreeSet;
1414

1515
/**
16+
* Data Source для музыкальных файлов. Осуществляет поиск всех музыкальных файлов в заданной папке и предоставляет доступ к итератору списка
17+
* {@link Path} отсортированному в по названиям.
18+
*
1619
* @author echernyshev
1720
* @since Jan 6, 2015
1821
*/
@@ -33,6 +36,12 @@ public static MusicFileDataSource create(Path source) throws IOException
3336
return result;
3437
}
3538

39+
@Override
40+
public Iterator<Path> iterator()
41+
{
42+
return files.iterator();
43+
}
44+
3645
private void walkFiles() throws IOException
3746
{
3847
Files.walkFileTree(source, new SimpleFileVisitor<Path>()
@@ -48,7 +57,7 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) th
4857
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
4958
{
5059
System.out.println("Processing file " + file.toString());
51-
if (file.toString().toLowerCase().endsWith(".mp3"))
60+
if (isMusicFile(file))
5261
{
5362
files.add(file);
5463
}
@@ -57,9 +66,8 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
5766
});
5867
}
5968

60-
@Override
61-
public Iterator<Path> iterator()
69+
private boolean isMusicFile(Path file)
6270
{
63-
return files.iterator();
71+
return file.toString().toLowerCase().endsWith(".mp3");
6472
}
6573
}

src/main/java/ru/kindteam/YatourFolderer.java

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,53 @@
22

33
import java.io.File;
44
import java.io.IOException;
5+
import java.nio.file.Path;
56
import java.nio.file.Paths;
67

8+
import org.apache.commons.cli.BasicParser;
9+
import org.apache.commons.cli.CommandLine;
10+
import org.apache.commons.cli.CommandLineParser;
11+
import org.apache.commons.cli.HelpFormatter;
12+
import org.apache.commons.cli.Options;
13+
import org.apache.commons.cli.ParseException;
14+
715
/**
8-
* Утилита для упаковки файлов по папкам для yatour M-06
16+
* Утилита для упаковки файлов по папкам для yatour M-06. Данный класс - точка входа в приложение.
917
*
1018
* @author echernyshev
1119
* @since Jan 2, 2015
1220
*/
1321
public class YatourFolderer
1422
{
15-
private static final String HELP = "Использование команды:\n"
16-
+ "java -jar yatour-folderer.jar /path/to/input/files /path/to/out";
23+
private final static class CopyParameters
24+
{
25+
CopyParameters(Path source, Path target)
26+
{
27+
this.source = source;
28+
this.target = target;
29+
}
30+
31+
Path source;
32+
Path target;
33+
}
34+
35+
private static Options OPTIONS = new Options();
36+
37+
static
38+
{
39+
OPTIONS.addOption("in", true, "Input folder, that contains music files to copy.");
40+
OPTIONS.addOption("out", true, "Output folder for copying music files.");
41+
}
1742

1843
public static void main( String[] args )
1944
{
20-
checkArguments(args);
45+
CopyParameters params = parseArguments(args);
46+
System.out.println(OPTIONS.toString());
2147
System.out.println("Processing files");
2248

2349
try
2450
{
25-
MusicFileCopier copier = new MusicFileCopier(Paths.get(args[0]), Paths.get(args[1]));
51+
MusicFileCopier copier = MusicFileCopier.create(params.source, params.target);
2652
copier.copyFiles();
2753
}
2854
catch (IOException e)
@@ -33,28 +59,50 @@ public static void main( String[] args )
3359
}
3460

3561

36-
private static void checkArguments(String[] args)
62+
private static CopyParameters parseArguments(String[] args)
3763
{
38-
if (args.length != 2)
64+
CommandLineParser parser = new BasicParser();
65+
try
66+
{
67+
CommandLine line = parser.parse(OPTIONS, args);
68+
if (!line.hasOption("in"))
69+
{
70+
printUsage("Bad syntax. Argument \"-in\" is required.");
71+
System.exit(1);
72+
}
73+
if (!line.hasOption("out"))
74+
{
75+
printUsage("Bad syntax. Argument \"-out\" is required.");
76+
System.exit(1);
77+
}
78+
String in = line.getOptionValue("in");
79+
String out = line.getOptionValue("out");
80+
checkFolder(in);
81+
checkFolder(out);
82+
return new CopyParameters(Paths.get(in), Paths.get(out));
83+
}
84+
catch (ParseException e)
3985
{
40-
printHelp("Количество агргументов должно равняться 2");
86+
printUsage("Parse command error: " + e.getMessage());
4187
System.exit(1);
88+
return null;
4289
}
43-
checkFolder(args[0]);
44-
checkFolder(args[1]);
4590
}
4691

47-
private static void printHelp(String error)
92+
private static void printUsage(String error)
4893
{
4994
System.out.println(error);
50-
System.out.println(HELP);
95+
HelpFormatter formatter = new HelpFormatter();
96+
formatter.printHelp(120,
97+
"java -jar yatour-folderer.jar -in /path/to/your/music -out /path/to/yatour/device",
98+
"Arguments: ", OPTIONS, "");
5199
}
52100

53101
private static void checkFolder(String path)
54102
{
55103
if (!new File(path).isDirectory())
56104
{
57-
printHelp(path + "\nНе является папкой!");
105+
printUsage(path + "\nNot a folder");
58106
System.exit(1);
59107
}
60108
}

0 commit comments

Comments
 (0)