diff --git a/pom.xml b/pom.xml index 409e349..f4fda19 100755 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 osm.surveyor ReStamp - 3.8.8-SNAPSHOT + 3.8.9-SNAPSHOT jar scm:git:http://surveyor.mydns.jp/gitbucket/git/haya4/restamp.git diff --git a/src/main/java/osm/surveyor/matchtime/ImgFile.java b/src/main/java/osm/surveyor/matchtime/ImgFile.java new file mode 100644 index 0000000..c6d127c --- /dev/null +++ b/src/main/java/osm/surveyor/matchtime/ImgFile.java @@ -0,0 +1,33 @@ +package osm.surveyor.matchtime; + +import java.io.File; +import java.util.Date; + +@SuppressWarnings("serial") +public class ImgFile extends File { + Date imgtime = null; + Date gpstime = null; + + public ImgFile(File file) { + super(file.getParentFile(), file.getName()); + } + + /* + public void setEnable(boolean enable) { + this.enable = enable; + } + + public boolean isEnable() { + return this.enable; + } + */ + + /** + * 対象は '*.JPG' のみ対象とする + * @return + */ + public boolean isImageFile() { + String name = this.getName(); + return ((name != null) && name.toUpperCase().endsWith(".JPG")); + } +} diff --git a/src/main/java/osm/surveyor/matchtime/ImgFileFilter.java b/src/main/java/osm/surveyor/matchtime/ImgFileFilter.java new file mode 100644 index 0000000..423b824 --- /dev/null +++ b/src/main/java/osm/surveyor/matchtime/ImgFileFilter.java @@ -0,0 +1,17 @@ +package osm.surveyor.matchtime; + +import java.io.File; +import java.io.FilenameFilter; + +/** + * JPEGファイルフィルター + * @author yuu + */ +public class ImgFileFilter implements FilenameFilter { + + @Override + public boolean accept(File dir, String name) { + return name.toUpperCase().matches(".*\\.JPG$"); + } + +} diff --git a/src/main/java/osm/surveyor/matchtime/ImgFolder.java b/src/main/java/osm/surveyor/matchtime/ImgFolder.java new file mode 100644 index 0000000..3e47179 --- /dev/null +++ b/src/main/java/osm/surveyor/matchtime/ImgFolder.java @@ -0,0 +1,37 @@ +package osm.surveyor.matchtime; + +import java.io.File; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; + +public class ImgFolder extends ArrayList { + private static final long serialVersionUID = 1L; + Path imgDir; + + public ImgFolder(Path imgDir) { + this.imgDir = imgDir; + File[] files = imgDir.toFile().listFiles(new ImgFileFilter()); + Arrays.sort(files, new FileSort()); + for (File file : files) { + this.add(new ImgFile(file)); + } + } + + public Path getImgDir() { + return this.imgDir; + } + + /** + * ファイル名の順序に並び替えるためのソートクラス + * + */ + static class FileSort implements Comparator { + @Override + public int compare(File src, File target){ + int diff = src.getName().compareTo(target.getName()); + return diff; + } + } +} diff --git a/src/main/java/osm/surveyor/matchtime/Restamp.java b/src/main/java/osm/surveyor/matchtime/Restamp.java index 1534f59..a04e858 100755 --- a/src/main/java/osm/surveyor/matchtime/Restamp.java +++ b/src/main/java/osm/surveyor/matchtime/Restamp.java @@ -6,14 +6,9 @@ import java.nio.file.Paths; import java.text.DateFormat; import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.Calendar; -import java.util.Comparator; import java.util.Date; -import java.util.List; import java.util.ResourceBundle; -import java.util.stream.Collectors; -import java.util.stream.Stream; /** * 動画から一定間隔で切り出したIMAGEファイルの更新日時を書き換える @@ -211,69 +206,55 @@ int bCount2 = 0; boolean base1 = false; boolean base2 = false; - ArrayList jpgFiles = new ArrayList<>(); // 指定されたディレクトリ内のJPEGファイルすべてを対象とする - try (Stream files = Files.list(Paths.get(imgDir.toString()))){ - List sortedList = files.sorted(Comparator.naturalOrder()).collect(Collectors.toList()); - - for (Path p : sortedList) { - if (Files.exists(p) && Files.isRegularFile(p)) { - String filename = p.getFileName().toString(); - if (filename.toUpperCase().endsWith(".JPG")) { - jpgFiles.add(p); - bCount1 += (base1 ? 0 : 1); - bCount2 += (base2 ? 0 : 1); - if (p.getFileName().equals(baseFile1.getFileName())) { - base1 = true; - } - if (p.getFileName().equals(baseFile2.getFileName())) { - base2 = true; - } - } - } + ImgFolder imgFolder = new ImgFolder(Paths.get(imgDir.toString())); + for (ImgFile img : imgFolder) { + bCount1 += (base1 ? 0 : 1); + bCount2 += (base2 ? 0 : 1); + if (img.getName().equals(baseFile1.toFile().getName())) { + base1 = true; } - if (!jpgFiles.isEmpty()) { - DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z"); - - // imgDir内の画像ファイルを処理する - long span = this.baseTime2.getTime() - this.baseTime1.getTime(); - span = span / (bCount2 - bCount1); - int i = 0; - System.out.println("-------------------------------"); - System.out.println("Update last modified date time."); - for (Path jpgFile : jpgFiles) { - long deltaMsec = (i - (bCount1 -1)) * span; - i++; - Calendar cal = Calendar.getInstance(); - cal.setTime(this.baseTime1); - cal.add(Calendar.MILLISECOND, (int) deltaMsec); - System.out.println(String.format("\t%s --> %s", df2.format(cal.getTime()), jpgFile.getFileName())); - - //------------------------------------------ - // ファイルをコピーして更新日時を変更する - //------------------------------------------ - try { - Path outFile; - if (outDir.equals(imgDir)) { - outFile = jpgFile; - } - else { - outFile = Paths.get(outDir.toString(), jpgFile.toFile().getName()); - Files.copy(jpgFile, outFile); - } - outFile.toFile().setLastModified(cal.getTimeInMillis()); - } - catch (Exception e) { - System.out.println("[ERROR] Can not convert."+ e.toString()); - } - } - System.out.println("-------------------------------"); + if (img.getName().equals(baseFile2.toFile().getName())) { + base2 = true; } } - catch(IOException e) { - e.printStackTrace(); - this.ex = new Exception(e); + if (!imgFolder.isEmpty()) { + DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); + + // imgDir内の画像ファイルを処理する + long span = this.baseTime2.getTime() - this.baseTime1.getTime(); + span = span / (bCount2 - bCount1); + int i = 0; + System.out.println("-------------------------------"); + System.out.println("Update last modified date time."); + for (ImgFile img : imgFolder) { + long deltaMsec = (i - (bCount1 -1)) * span; + i++; + Calendar cal = Calendar.getInstance(); + cal.setTime(this.baseTime1); + cal.add(Calendar.MILLISECOND, (int) deltaMsec); + System.out.println(String.format("\t%s --> %s", df2.format(cal.getTime()), img.getName())); + + //------------------------------------------ + // ファイルをコピーして更新日時を変更する + //------------------------------------------ + try { + Path outFile; + if (outDir.equals(imgDir)) { + outFile = img.toPath(); + } + else { + outFile = Paths.get(outDir.toString(), img.getName()); + Files.copy(img.toPath(), outFile); + } + outFile.toFile().setLastModified(cal.getTimeInMillis()); + } + catch (Exception e) { + System.out.println("[ERROR] Can not convert."+ e.toString()); + } + } + System.out.println("-------------------------------"); } } } \ No newline at end of file