[Fix] Don't read XML files starting with .tmp_ our temp file prefix
This commit is contained in:
parent
320fc01624
commit
898afd98b9
|
@ -46,13 +46,14 @@ public class FileIo {
|
||||||
public static final String DEFAULT_ENCODING = "utf-8"; //$NON-NLS-1$
|
public static final String DEFAULT_ENCODING = "utf-8"; //$NON-NLS-1$
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(FileIo.class);
|
private static final Logger logger = LoggerFactory.getLogger(FileIo.class);
|
||||||
|
public static final String TMP_PREFIX = ".tmp_";
|
||||||
|
|
||||||
private final File path;
|
private final File path;
|
||||||
private final File tmpPath;
|
private final File tmpPath;
|
||||||
|
|
||||||
public FileIo(File path) {
|
public FileIo(File path) {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
this.tmpPath = new File(this.path.getParentFile(), ".tmp_" + this.path.getName());
|
this.tmpPath = new File(this.path.getParentFile(), TMP_PREFIX + this.path.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> void writeSax(PersistenceContext<T> ctx) {
|
public <T> void writeSax(PersistenceContext<T> ctx) {
|
||||||
|
@ -160,7 +161,7 @@ public class FileIo {
|
||||||
|
|
||||||
// Transform to file
|
// Transform to file
|
||||||
try (Writer ioWriter = new OutputStreamWriter(new FileOutputStream(this.tmpPath), encoding)) {
|
try (Writer ioWriter = new OutputStreamWriter(new FileOutputStream(this.tmpPath), encoding)) {
|
||||||
StreamResult result = new StreamResult(this.tmpPath);
|
StreamResult result = new StreamResult(ioWriter);
|
||||||
Source xmlSource = new DOMSource(document);
|
Source xmlSource = new DOMSource(document);
|
||||||
transformer.transform(xmlSource, result);
|
transformer.transform(xmlSource, result);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.xmlpers.api;
|
package li.strolch.xmlpers.api;
|
||||||
|
|
||||||
|
import static li.strolch.xmlpers.api.FileIo.TMP_PREFIX;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -138,12 +140,14 @@ public class MetadataDao {
|
||||||
|
|
||||||
Set<String> keySet = new TreeSet<>();
|
Set<String> keySet = new TreeSet<>();
|
||||||
File[] subTypeFiles = queryPath.listFiles();
|
File[] subTypeFiles = queryPath.listFiles();
|
||||||
|
if (subTypeFiles != null) {
|
||||||
for (File subTypeFile : subTypeFiles) {
|
for (File subTypeFile : subTypeFiles) {
|
||||||
if (subTypeFile.isDirectory()) {
|
if (subTypeFile.isDirectory()) {
|
||||||
String type = subTypeFile.getName();
|
String type = subTypeFile.getName();
|
||||||
keySet.add(type);
|
keySet.add(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return keySet;
|
return keySet;
|
||||||
}
|
}
|
||||||
|
@ -178,7 +182,7 @@ public class MetadataDao {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (File subTypeFile : subTypeFiles) {
|
for (File subTypeFile : subTypeFiles) {
|
||||||
if (subTypeFile.isFile()) {
|
if (subTypeFile.isFile() && !subTypeFile.getName().startsWith(TMP_PREFIX)) {
|
||||||
String filename = subTypeFile.getName();
|
String filename = subTypeFile.getName();
|
||||||
String id = FilenameUtility.getId(filename);
|
String id = FilenameUtility.getId(filename);
|
||||||
keySet.add(id);
|
keySet.add(id);
|
||||||
|
@ -206,14 +210,16 @@ public class MetadataDao {
|
||||||
throw new IllegalArgumentException(msg);
|
throw new IllegalArgumentException(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
long numberOfFiles = 0l;
|
long numberOfFiles = 0L;
|
||||||
|
|
||||||
File[] subTypeFiles = queryPath.listFiles();
|
File[] subTypeFiles = queryPath.listFiles();
|
||||||
|
if (subTypeFiles != null) {
|
||||||
for (File subTypeFile : subTypeFiles) {
|
for (File subTypeFile : subTypeFiles) {
|
||||||
|
|
||||||
if (subTypeFile.isDirectory())
|
if (subTypeFile.isDirectory())
|
||||||
numberOfFiles++;
|
numberOfFiles++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return numberOfFiles;
|
return numberOfFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,14 +241,16 @@ public class MetadataDao {
|
||||||
throw new IllegalArgumentException(msg);
|
throw new IllegalArgumentException(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
long numberOfFiles = 0l;
|
long numberOfFiles = 0L;
|
||||||
|
|
||||||
File[] subTypeFiles = queryPath.listFiles();
|
File[] subTypeFiles = queryPath.listFiles();
|
||||||
|
if (subTypeFiles != null) {
|
||||||
for (File subTypeFile : subTypeFiles) {
|
for (File subTypeFile : subTypeFiles) {
|
||||||
|
|
||||||
if (subTypeFile.isFile())
|
if (subTypeFile.isFile() && !subTypeFile.getName().startsWith(TMP_PREFIX))
|
||||||
numberOfFiles++;
|
numberOfFiles++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return numberOfFiles;
|
return numberOfFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue