+ Add UI candy. + Make sub-packages. + Add PDF split feature. - fileCut.sh - routines.RetrieveSubFies.java - update to Tools.java + Add a logo/icon.master
parent
b1f7b33442
commit
7270d1cb4e
After Width: | Height: | Size: 19 KiB |
@ -0,0 +1,49 @@
|
|||||||
|
package app.routines;
|
||||||
|
|
||||||
|
import app.Execute;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class FilePool {
|
||||||
|
|
||||||
|
private final Execute x = new Execute();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [1] Write output of <b>find srcdir</b> to <b>/tmp/find</b> .<br>
|
||||||
|
* [2] Read <b>/tmp/find</b> into <b>List< String /></b> .<br>
|
||||||
|
* [3] Add <b>List< String /></b> entries to <b>Map>String,File></b> , where
|
||||||
|
* <b>String</b> is an <b>int</b> key. <br>
|
||||||
|
*
|
||||||
|
* @param srcdir <i>String</i>
|
||||||
|
* @param type <i>String</i> "file" OR "dir" , pick what type will be loaded.
|
||||||
|
* @return filepool
|
||||||
|
*/
|
||||||
|
public Map<Integer, File> loadPool(String srcdir, String type) {
|
||||||
|
// [1]
|
||||||
|
x.execute(new String[]{System.getProperty("user.dir") + "/src/app/shell/toFile.sh", "find", srcdir, "/tmp/find"});
|
||||||
|
// [2]
|
||||||
|
List<String> lines = null;
|
||||||
|
try {
|
||||||
|
lines = Files.readAllLines(Paths.get("/tmp/find"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
// [3]
|
||||||
|
Map<Integer, File> filepool = new HashMap<>();
|
||||||
|
int j = 0;
|
||||||
|
for (String line : lines) {
|
||||||
|
File file = new File(line);
|
||||||
|
if (type == "dir" && file.isDirectory() || type == "file" && file.isFile()) {
|
||||||
|
filepool.put(j, file);
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filepool;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,114 @@
|
|||||||
|
package app.routines;
|
||||||
|
|
||||||
|
import app.Execute;
|
||||||
|
import app.Tools;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class RetrieveSubFiles {
|
||||||
|
|
||||||
|
private final Execute x;
|
||||||
|
private final Tools tools;
|
||||||
|
|
||||||
|
|
||||||
|
public RetrieveSubFiles() {
|
||||||
|
this.x = new Execute();
|
||||||
|
this.tools = new Tools();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param pool Map< Integer, File /> , a map containing files.
|
||||||
|
* @return create subfiles on disk. MFile /> of duplicates contained in <b>md5Pool</b>
|
||||||
|
*/
|
||||||
|
public int pdf_method(Map<Integer, File> pool) {
|
||||||
|
|
||||||
|
int files_created = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < pool.size(); i++) {
|
||||||
|
|
||||||
|
File file = pool.get(i);
|
||||||
|
String f_path = file.getAbsolutePath();
|
||||||
|
if (f_path.endsWith("pdf")) {
|
||||||
|
// -n is for adding line numbers
|
||||||
|
// -a is for accepting binary input
|
||||||
|
// -T is for preserving tabs, this helps in some special cases.
|
||||||
|
String[] cmd = new String[]{System.getProperty("user.dir") + "/src/app/shell/pipe.sh",
|
||||||
|
"cat " + f_path,
|
||||||
|
"grep -naT %PDF"};
|
||||||
|
String pdf = tools.brToString(x.execute(cmd).output);
|
||||||
|
// because -T was used, we now must use regex to extract the '1234:' tag
|
||||||
|
String pdf_lines = tools.matchRegEx(pdf, "[0-9]+:");
|
||||||
|
|
||||||
|
cmd = new String[]{System.getProperty("user.dir") + "/src/app/shell/pipe.sh",
|
||||||
|
"cat " + f_path,
|
||||||
|
"grep -naT %%EOF"};
|
||||||
|
String eof = tools.brToString(x.execute(cmd).output);
|
||||||
|
String eof_lines = tools.matchRegEx(eof, "[0-9]+:");
|
||||||
|
|
||||||
|
// TODO because of PDF tags having 'error char' instad of line nums, the # of PDF tags < # EOF tags
|
||||||
|
// TODO fix this by maybe making a grep of grep
|
||||||
|
List<String> pdf_list = pdf_list(pdf_lines, eof_lines);
|
||||||
|
int adf = 3;
|
||||||
|
|
||||||
|
for (int j = 0; j < pdf_list.size(); j++) {
|
||||||
|
String sub_f_name = file.getName().split("\\.")[0] + "-sub" + j + ".pdf";
|
||||||
|
String[] split = pdf_list.get(j).split(":");
|
||||||
|
|
||||||
|
cmd = new String[]{System.getProperty("user.dir") + "/src/app/shell/fileCut.sh",
|
||||||
|
f_path,
|
||||||
|
split[0],
|
||||||
|
split[1],
|
||||||
|
file.getParent() + "/" + sub_f_name};
|
||||||
|
x.execute(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
files_created += pdf_list.size();
|
||||||
|
// x.execute(new String[]{"rm", f_path});
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Do nothing. File is either not a PDF,
|
||||||
|
// or contains no usable %PDF and %%EOF sequences.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return files_created;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pdf_matrix contains rows for each subfile as hinted by <i>params</i>:<br>
|
||||||
|
* [ %PDF line ; %%EOF line ; %PDF-version ; %%EOF ]
|
||||||
|
*
|
||||||
|
* @param pdf Record of lines containing the %PDF sequence.
|
||||||
|
* @param eof Record of lines containing the %%EOF sequence.
|
||||||
|
* @return pdf_matrix, see above.
|
||||||
|
*/
|
||||||
|
public List<String> pdf_list(String pdf, String eof) {
|
||||||
|
List<String> list = new ArrayList<String>();
|
||||||
|
|
||||||
|
String[] pdf_list = pdf.split("\n");
|
||||||
|
String[] eof_list = eof.split("\n");
|
||||||
|
|
||||||
|
if (pdf_list.length == eof_list.length) {
|
||||||
|
for (int j = 0; j < pdf_list.length; j++) {
|
||||||
|
String pdf_tag_line = pdf_list[j].split(":")[0];
|
||||||
|
String eof_tag_line = eof_list[j].split(":")[0];
|
||||||
|
list.add(pdf_tag_line + ":" + eof_tag_line);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error("Number of %PDF tags does not match the number %%EOF tags. Skipping this file.");
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# ================================================================================
|
||||||
|
# FILE: fileCut.sh
|
||||||
|
#
|
||||||
|
# USAGE: fileCut.sh [input file] [cut start] [cut end] [output file]
|
||||||
|
#
|
||||||
|
# DESCRIPTION: Cuts section between 'cut start' and 'cut end' from 'input file'
|
||||||
|
# and writes the contents of the cut to 'output file'.
|
||||||
|
#
|
||||||
|
# ================================================================================
|
||||||
|
|
||||||
|
input_file=$1
|
||||||
|
start_cut=$2
|
||||||
|
end_cut=$3
|
||||||
|
output_file=$4
|
||||||
|
let cut_size=$end_cut-$start_cut
|
||||||
|
|
||||||
|
|
||||||
|
head -n $start_cut $input_file | tail -n 1 | sed 's/.*%PDF/%PDF/g' > $output_file
|
||||||
|
|
||||||
|
|
||||||
|
head -n $end_cut $input_file | tail -n $cut_size >> $output_file
|
@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
a=$1
|
||||||
|
b=$2
|
||||||
|
$a | $b
|
||||||
|
|
||||||
|
# this is a pipe
|
@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
a=$1
|
||||||
|
b=$2
|
||||||
|
c=$3
|
||||||
|
$a | $b | $c
|
||||||
|
|
||||||
|
# this is a double pipe
|
Loading…
Reference in new issue