-
Notifications
You must be signed in to change notification settings - Fork 74
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
1 parent
f320e24
commit f1f9d3a
Showing
36 changed files
with
835 additions
and
341 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
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
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
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
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
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
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
106 changes: 106 additions & 0 deletions
106
nop-core/src/main/java/io/nop/core/resource/impl/DynamicResource.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,106 @@ | ||
/** | ||
* Copyright (c) 2017-2023 Nop Platform. All rights reserved. | ||
* Author: [email protected] | ||
* Blog: https://www.zhihu.com/people/canonical-entropy | ||
* Gitee: https://gitee.com/canonical-entropy/nop-chaos | ||
* Github: https://github.com/entropy-cloud/nop-chaos | ||
*/ | ||
package io.nop.core.resource.impl; | ||
|
||
import io.nop.api.core.exceptions.NopException; | ||
import io.nop.api.core.util.Guard; | ||
import io.nop.core.resource.IFile; | ||
import io.nop.core.resource.IResource; | ||
import io.nop.core.resource.ResourceConstants; | ||
|
||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
import static io.nop.core.CoreErrors.ARG_RESOURCE_PATH; | ||
import static io.nop.core.CoreErrors.ERR_RESOURCE_UNKNOWN_RESOURCE_NOT_ALLOW_OPERATION; | ||
|
||
/** | ||
* IResourceStore解析resourcePath失败时,将会返回UnknownResource | ||
* | ||
* @author [email protected] | ||
*/ | ||
public class DynamicResource extends AbstractResource implements IFile { | ||
|
||
private static final long serialVersionUID = 3061171246553624932L; | ||
|
||
private final static AtomicLong s_seq = new AtomicLong(); | ||
|
||
public DynamicResource(String path) { | ||
super(path); | ||
Guard.checkArgument(path.startsWith(ResourceConstants.DYNAMIC_NS_PREFIX)); | ||
} | ||
|
||
public static String newDynamicPath() { | ||
return ResourceConstants.DYNAMIC_NS_PREFIX + s_seq.incrementAndGet(); | ||
} | ||
|
||
@Override | ||
public boolean exists() { | ||
return true; | ||
} | ||
|
||
@Override | ||
protected Object internalObj() { | ||
return getPath(); | ||
} | ||
|
||
NopException error() { | ||
return new NopException(ERR_RESOURCE_UNKNOWN_RESOURCE_NOT_ALLOW_OPERATION).param(ARG_RESOURCE_PATH, getPath()); | ||
} | ||
|
||
@Override | ||
public InputStream getInputStream() { | ||
throw error(); | ||
} | ||
|
||
@Override | ||
public boolean isReadOnly() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public OutputStream getOutputStream(boolean append) { | ||
throw error(); | ||
} | ||
|
||
@Override | ||
public boolean mkdirs() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean createNewFile() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public IFile createTempFile(String prefix, String postfix) { | ||
throw error(); | ||
} | ||
|
||
@Override | ||
public boolean renameTo(IResource resource) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public IFile getResource(String relativeName) { | ||
return new DynamicResource(getPath() + relativeName); | ||
} | ||
|
||
@Override | ||
public List<IFile> getChildren() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void deleteOnExit() { | ||
} | ||
} |
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
nop-core/src/main/java/io/nop/core/resource/store/DynamicNamespaceHandler.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 @@ | ||
/** | ||
* Copyright (c) 2017-2023 Nop Platform. All rights reserved. | ||
* Author: [email protected] | ||
* Blog: https://www.zhihu.com/people/canonical-entropy | ||
* Gitee: https://gitee.com/canonical-entropy/nop-chaos | ||
* Github: https://github.com/entropy-cloud/nop-chaos | ||
*/ | ||
package io.nop.core.resource.store; | ||
|
||
import io.nop.core.resource.IResource; | ||
import io.nop.core.resource.IResourceNamespaceHandler; | ||
import io.nop.core.resource.IResourceStore; | ||
import io.nop.core.resource.ResourceConstants; | ||
import io.nop.core.resource.impl.DynamicResource; | ||
|
||
public class DynamicNamespaceHandler implements IResourceNamespaceHandler { | ||
public static final DynamicNamespaceHandler INSTANCE = new DynamicNamespaceHandler(); | ||
|
||
@Override | ||
public String getNamespace() { | ||
return ResourceConstants.DYNAMIC_NS; | ||
} | ||
|
||
@Override | ||
public IResource getResource(String vPath, IResourceStore locator) { | ||
return new DynamicResource(vPath); | ||
} | ||
} |
Oops, something went wrong.