Skip to content

Commit

Permalink
Added last basic API-Classes
Browse files Browse the repository at this point in the history
Added ForwardingFileSystem as delegator for method-calls between EasyDokanFileSystem-implementations and DokanFileSystem-API
Added EasyDokanFileSystemStub as stub for implementations of EasyDokanFileSystem (similiar to DokanFileSystemStub)
Added AbstractEasyDokanFileSystem as base class for implementations of EasyDokanFileSystem (similiar to AbstractDokanFileSystem)

This commit is part of my effort to fix dokan-java's issue dokan-dev#32
  • Loading branch information
JaniruTEC committed May 28, 2020
1 parent 461777d commit 98e1497
Show file tree
Hide file tree
Showing 3 changed files with 527 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package dev.dokan.dokan_java.wrappers;

import dev.dokan.dokan_java.NativeName;
import dev.dokan.dokan_java.FileSystemInformation;
import dev.dokan.dokan_java.NotImplemented;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;

public abstract class AbstractEasyDokanFileSystem implements EasyDokanFileSystem {

private final Set<String> notImplementedMethods;
private final ForwardingFileSystem lowLevelFS;

public AbstractEasyDokanFileSystem(FileSystemInformation fileSystemInformation) {
this.notImplementedMethods = Arrays.stream(getClass().getMethods())
.filter(method -> method.getAnnotation(NotImplemented.class) != null)
.map((method) -> getNativeName(method))
.collect(Collectors.toSet());

this.lowLevelFS = new ForwardingFileSystem(fileSystemInformation, this.notImplementedMethods, this);
}

private String getNativeName(Method method) {
Method annotated = getAnnotatedMethod(NativeName.class, method);

if(annotated == null) {
return method.getName();
}
return annotated.getAnnotation(NativeName.class).value();
}

private Method getAnnotatedMethod(Class<? extends Annotation> annotation, Method method) {
return getAnnotatedMethod(annotation, method.getDeclaringClass(), method.getName(), method.getParameterTypes());
}

private Method getAnnotatedMethod(Class<? extends Annotation> annotation,
Class<?> inClass,
String methodName,
Class<?>... parameterTypes) {

Method result;
try {
result = inClass.getMethod(methodName, parameterTypes);
} catch(NoSuchMethodException e) {
return null;
}

if(result.isAnnotationPresent(annotation)) {
return result;
}

Class<?> superClass = inClass.getSuperclass();
if(superClass != null) {
result = getAnnotatedMethod(annotation, superClass, methodName, parameterTypes);
}

if(result != null) {
return result;
}

return Arrays.stream(inClass.getInterfaces())
.map((cInterface) -> getAnnotatedMethod(annotation, cInterface, methodName, parameterTypes))
.findFirst().orElse(null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
package dev.dokan.dokan_java.wrappers;

import dev.dokan.dokan_java.FileSystemInformation;
import dev.dokan.dokan_java.NotImplemented;
import dev.dokan.dokan_java.constants.microsoft.CreateOption;
import dev.dokan.dokan_java.constants.microsoft.CreationDisposition;
import dev.dokan.dokan_java.constants.microsoft.FileAttribute;
import dev.dokan.dokan_java.constants.microsoft.FileShareAccess;
import dev.dokan.dokan_java.structure.EnumIntegerSet;
import dev.dokan.dokan_java.structure.filesecurity.SelfRelativeSecurityDescriptor;

import java.nio.file.Path;
import java.nio.file.attribute.FileTime;
import java.util.Collection;

public class EasyDokanFileSystemStub extends AbstractEasyDokanFileSystem {

public EasyDokanFileSystemStub(FileSystemInformation fileSystemInformation) {
super(fileSystemInformation);
}

@NotImplemented
@Override
public void createHandle(Path absolutePath,
String relativePath,
EasyDokanIOSecurityContext securityContext,
DesiredAccessMask desiredAccess,
EnumIntegerSet<FileAttribute> fileAttributes,
EnumIntegerSet<FileShareAccess> shareAccess,
CreationDisposition creationDisposition,
EnumIntegerSet<CreateOption> createOptions,
DokanFileHandle dokanFileHandle) {

}

@NotImplemented
@Override
public void cleanup(Path absolutePath, String relativePath, DokanFileHandle dokanFileHandle) {

}

@NotImplemented
@Override
public void closeHandle(Path absolutePath, String relativePath, DokanFileHandle dokanFileHandle) {

}

@NotImplemented
@Override
public byte[] readFile(Path absolutePath,
String relativePath,
long offset,
int readLength,
DokanFileHandle dokanFileHandle) {
return new byte[0];
}

@NotImplemented
@Override
public int writeFile(Path absolutePath,
String relativePath,
byte[] buffer,
long offset,
DokanFileHandle dokanFileHandle) {
return 0;
}

@NotImplemented
@Override
public void flush(Path absolutePath, String relativePath, DokanFileHandle dokanFileHandle) {

}

@NotImplemented
@Override
public EasyFileInfo getFileInformation(Path absolutePath, String relativePath, DokanFileHandle dokanFileHandle) {
return null;
}

@NotImplemented
@Override
public Collection<FindFileInfo> findFiles(Path absolutePath, String relativePath, DokanFileHandle dokanFileHandle) {
return null;
}

@NotImplemented
@Override
public Collection<FindFileInfo> findFilesWithPattern(Path absolutePath,
String relativePath,
String pattern,
DokanFileHandle dokanFileHandle) {
return null;
}

@NotImplemented
@Override
public void setFileAttributes(Path absolutePath,
String relativePath,
EnumIntegerSet<FileAttribute> fileAttributes,
DokanFileHandle dokanFileHandle) {

}

@NotImplemented
@Override
public void setFileTime(Path absolutePath,
String relativePath,
FileTime creationTime,
FileTime lastAccessTime,
FileTime lastWriteTime,
DokanFileHandle dokanFileHandle) {

}

@NotImplemented
@Override
public void prepareDeleteFile(Path absolutePath, String relativePath, DokanFileHandle dokanFileHandle) {

}

@NotImplemented
@Override
public void prepareDeleteDirectory(Path absolutePath, String relativePath, DokanFileHandle dokanFileHandle) {

}

@NotImplemented
@Override
public void moveFile(Path sourceAbsolutePath,
String sourceRelativePath,
Path destinationAbsolutePath,
String destinationRelativePath,
boolean replaceIfExisting,
DokanFileHandle dokanFileHandle) {

}

@NotImplemented
@Override
public void setEndOfFile(Path absolutePath, String relativePath, long fileSize, DokanFileHandle dokanFileHandle) {

}

@NotImplemented
@Override
public void setAllocationSize(Path absolutePath,
String relativePath,
long allocationSize,
DokanFileHandle dokanFileHandle) {

}

@NotImplemented
@Override
public void lockFile(Path absolutePath,
String relativePath,
long lockOffset,
long lockLength,
DokanFileHandle dokanFileHandle) {

}

@NotImplemented
@Override
public void unlockFile(Path absolutePath,
String relativePath,
long lockOffset,
long lockLength,
DokanFileHandle dokanFileHandle) {

}

@NotImplemented
@Override
public DiskSpaceInfo getDiskSpaceInfo(DokanFileHandle dokanFileHandle) {
return null;
}

@NotImplemented
@Override
public VolumeInformation getVolumeInformation(DokanFileHandle dokanFileHandle) {
return null;
}

@NotImplemented
@Override
public void mounted(DokanFileHandle dokanFileHandle) {

}

@NotImplemented
@Override
public void unmounted(DokanFileHandle dokanFileHandle) {

}

@NotImplemented
@Override
public SelfRelativeSecurityDescriptor getFileSecurity(Path absolutePath,
String relativePath,
DesiredAccessMask requestedDescriptorInfo,
int availableLength,
DokanFileHandle dokanFileHandle) {
return null;
}

@NotImplemented
@Override
public void setFileSecurity(Path absolutePath,
String relativePath,
DesiredAccessMask suppliedDescriptorInfo,
SelfRelativeSecurityDescriptor securityDescriptor,
int availableLength,
DokanFileHandle dokanFileHandle) {

}
}
Loading

0 comments on commit 98e1497

Please sign in to comment.