-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
175 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
components/src/main/java/com/dlsc/jfxcentral2/utils/EmptyEntityResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.dlsc.jfxcentral2.utils; | ||
|
||
import org.xml.sax.EntityResolver; | ||
import org.xml.sax.InputSource; | ||
|
||
import java.io.StringReader; | ||
/** | ||
* EmptyEntityResolver is a singleton implementation of the EntityResolver interface. | ||
* Its main purpose is to prevent the XML parser from trying to access external DTDs or schemas | ||
* when parsing an XML document. This can be particularly useful to avoid unnecessary network | ||
* requests or potential blocking issues, such as getting HTTP 429 response codes. | ||
* | ||
* By providing an empty InputSource, we essentially tell the XML parser that there are no external | ||
* entities to resolve, and it should continue parsing without trying to fetch them. | ||
* | ||
* Typical use case: | ||
* When parsing SVG or any XML documents that reference external DTDs or schemas, | ||
* you can use this resolver to speed up parsing and avoid potential network-related issues. | ||
* | ||
*/ | ||
public enum EmptyEntityResolver implements EntityResolver { | ||
INSTANCE; | ||
|
||
@Override | ||
public InputSource resolveEntity(String publicId, String systemId) { | ||
return new InputSource(new StringReader("")); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
components/src/main/java/com/dlsc/jfxcentral2/utils/FileUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.dlsc.jfxcentral2.utils; | ||
|
||
import java.io.File; | ||
|
||
public class FileUtil { | ||
|
||
/** | ||
* Deletes files within a directory while skipping files that are in use. | ||
* Delete files as much as possible, ignoring occupied files | ||
* @param directory the directory to clear | ||
*/ | ||
public static void clearDirectory(File directory) { | ||
// check directory | ||
if (directory == null || !directory.exists() || !directory.isDirectory()) { | ||
return; | ||
} | ||
|
||
File[] files = directory.listFiles(); | ||
if (files == null) { | ||
return; | ||
} | ||
|
||
for (File file : files) { | ||
if (file.isFile()) { | ||
// Ignore file deletion results; | ||
// Because the file may be in use and cannot be deleted, we just have to try to delete it. | ||
file.delete(); | ||
} else if (file.isDirectory()) { | ||
clearDirectory(file); | ||
file.delete(); | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.