Add FileAccess class with many exceptions
The FileAccess class is an almost 1:1 rewrite of the old FileAccess class from v1-alpha9, just with some method names changed, a set of "verify" methods, no setPosixPermissions method anymore and wrapper exceptions around Java exceptions to avoid direct contact with Java stuff for public API. See the NonKotlinContact annotation for more information.
The old FileAccess class (for reference): 1e978e3146/base/src/main/java/de/staropensource/engine/base/utility/FileAccess.java
This commit is contained in:
parent
56152536f9
commit
8393818043
8 changed files with 1546 additions and 0 deletions
|
@ -21,6 +21,7 @@
|
|||
package de.staropensource.engine.base
|
||||
|
||||
import de.staropensource.engine.base.utility.Environment
|
||||
import de.staropensource.engine.base.utility.FileAccess
|
||||
import de.staropensource.engine.logging.Logger
|
||||
|
||||
/**
|
||||
|
@ -120,6 +121,7 @@ class Engine private constructor() {
|
|||
|
||||
// Run initialization code
|
||||
Environment.detect()
|
||||
FileAccess.updateDefaultPaths()
|
||||
|
||||
state = State.INITIALIZED
|
||||
}
|
||||
|
@ -142,6 +144,7 @@ class Engine private constructor() {
|
|||
|
||||
// Run shutdown code
|
||||
Environment.unset()
|
||||
FileAccess.unsetDefaultPaths()
|
||||
|
||||
state = State.SHUT_DOWN
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
* with an exception allowing classpath linking.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.exception
|
||||
|
||||
/**
|
||||
* Thrown when being unable to
|
||||
* find a file or directory.
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
class FileOrDirectoryNotFoundException(val path: String, val throwable: Throwable? = null) : RuntimeException("The file or directory '${path}' could not be found", throwable)
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
* with an exception allowing classpath linking.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.exception
|
||||
|
||||
/**
|
||||
* Thrown when reading a file fails
|
||||
* due to it being larger than the
|
||||
* configured max heap size.
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
class FileTooLargeException(val path: String, val throwable: Throwable? = null) : RuntimeException("Unable to read file '${path}' as it is larger than the configured heap size", throwable)
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
* with an exception allowing classpath linking.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.exception
|
||||
|
||||
/**
|
||||
* Thrown when an IO error occurs.
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
class IOAccessException(val error: String? = null, val throwable: Throwable? = null) : RuntimeException(error, throwable)
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
* with an exception allowing classpath linking.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.exception
|
||||
|
||||
/**
|
||||
* Thrown when a verification fails.
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
class VerificationFailedException(val error: String? = null, val throwable: Throwable? = null) : RuntimeException(error, throwable)
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
* with an exception allowing classpath linking.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Exceptions thrown by the engine.
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
package de.staropensource.engine.base.exception
|
File diff suppressed because it is too large
Load diff
8
dist/detekt.yml
vendored
8
dist/detekt.yml
vendored
|
@ -18,6 +18,10 @@ build:
|
|||
complexity:
|
||||
TooManyFunctions:
|
||||
active: false
|
||||
NestedBlockDepth:
|
||||
threshold: 6
|
||||
ComplexCondition:
|
||||
active: false
|
||||
|
||||
naming:
|
||||
MemberNameEqualsClassName:
|
||||
|
@ -38,3 +42,7 @@ style:
|
|||
active: false
|
||||
UnusedParameter:
|
||||
active: false
|
||||
ReturnCount:
|
||||
active: false
|
||||
WildcardImport:
|
||||
active: false
|
||||
|
|
Loading…
Reference in a new issue