initial commit
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
package com.bayer.edam;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.List;
|
||||
|
||||
import com.univocity.parsers.csv.CsvParser;
|
||||
import com.univocity.parsers.csv.CsvParserSettings;
|
||||
|
||||
public class ToolboxFileExporter {
|
||||
|
||||
|
||||
private List<String[]> rows;
|
||||
private String baseDir = "I:\\ToolboxAssets";
|
||||
|
||||
// Formatdatei generiert mit
|
||||
// bcp "SELECT OriginalImage FROM AssetImages WHERE AssetID=586" queryout Image.jpg -S MOVNCG -d Bayertoolbox_prod -T -x
|
||||
// Geben Sie den Dateispeichertyp des Felds OriginalImage ein [varbinary(max)]: x
|
||||
// Geben Sie die Präfixlänge des OriginalImage-Felds ein [8]:
|
||||
// Geben Sie das Feldabschlusszeichen ein [none]:
|
||||
|
||||
// Abruf:
|
||||
// bcp "SELECT OriginalImage FROM AssetImages WHERE AssetID=586" queryout Image5.jpg -S MOVNCG -d Bayertoolbox_prod -T -f bcp.fmt
|
||||
|
||||
private String command1 = "bcp \"SELECT OriginalImage FROM AssetImages WHERE AssetID=";
|
||||
private String command2 = "\" queryout ";
|
||||
private String command3 = " -S MOVNCG -d Bayertoolbox_prod -T -f bcp.fmt";
|
||||
|
||||
private File workingDir = new File(baseDir);
|
||||
|
||||
public ToolboxFileExporter() throws Exception {
|
||||
readList();
|
||||
|
||||
for (int i=0; i < 3; i++) {
|
||||
getImage(rows.get(188+i)[1]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void getImage(String assetId) throws Exception {
|
||||
System.out.println("AssetID: " + assetId);
|
||||
|
||||
// TODO Check if file already exists (bcp just overwrites existing files)
|
||||
|
||||
Process process = Runtime.getRuntime().exec(command1 + assetId + command2 + "Test5.jpg" + command3, null, workingDir);
|
||||
process.waitFor();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
|
||||
String s;
|
||||
while ((s = reader.readLine()) != null) {
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
|
||||
private void readList() {
|
||||
CsvParserSettings settings = new CsvParserSettings();
|
||||
settings.getFormat().setLineSeparator("\r\n");
|
||||
settings.getFormat().setDelimiter(';');
|
||||
settings.getFormat().setCharToEscapeQuoteEscaping('"');
|
||||
settings.setHeaderExtractionEnabled(false);
|
||||
|
||||
CsvParser parser = new CsvParser(settings);
|
||||
|
||||
rows = parser.parseAll(new File("I:\\ToolboxAssets\\AssetImages.csv"));
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
new ToolboxFileExporter();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user