Package org.mockserver.file
Class FileCreator
java.lang.Object
org.mockserver.file.FileCreator
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic FilecreateFileIfNotExists(String type, File file) static voidcreateParentDirs(File file) static voidwriteToFileAtomically(String type, File target, byte[] content, boolean ownerOnly) Binary variant ofwriteToFileAtomically(String, File, String, boolean)— see that method for the atomicity and permission guarantees.static voidwriteToFileAtomically(String type, File target, String content, boolean ownerOnly) Atomically writecontenttotarget, applying restrictive owner-only permissions (0600) whenownerOnlyis true (private keys, key stores) or world-readable (0644) permissions otherwise (public certificates), on POSIX filesystems.
-
Constructor Details
-
FileCreator
public FileCreator()
-
-
Method Details
-
writeToFileAtomically
public static void writeToFileAtomically(String type, File target, String content, boolean ownerOnly) throws IOException Atomically writecontenttotarget, applying restrictive owner-only permissions (0600) whenownerOnlyis true (private keys, key stores) or world-readable (0644) permissions otherwise (public certificates), on POSIX filesystems.The bytes are written to a sibling temp file (created up-front with the target permissions, so a private key is never momentarily world-readable) then moved into place with
ATOMIC_MOVEwhere supported, so a concurrent reader never observes a truncated or empty file. On non-POSIX filesystems (e.g. Windows) the permission step is skipped and the platform default is used — the atomic write still applies.- Parameters:
type- human-readable description of the artefact, used in the failure messagetarget- the destination filecontent- the file content (UTF-8 encoded)ownerOnly- true to restrict to the owning user (private key material), false for public data- Throws:
IOException- if the parent directory is missing/unwritable, or the write/move fails — the caller MUST fail fast rather than swallow this, otherwise a later read surfaces a misleading "cannot read PEM" error (defect C13)
-
writeToFileAtomically
public static void writeToFileAtomically(String type, File target, byte[] content, boolean ownerOnly) throws IOException Binary variant ofwriteToFileAtomically(String, File, String, boolean)— see that method for the atomicity and permission guarantees. Used for key stores (JKS) that carry private key material and must be owner-only (0600).- Throws:
IOException
-
createFileIfNotExists
-
createParentDirs
- Throws:
IOException
-