com.jtransc.io.async.JTranscAsyncFile Maven / Gradle / Ivy
package com.jtransc.io.async;
import com.jtransc.async.JTranscAsyncHandler;
import com.jtransc.io.JTranscFileMode;
import com.jtransc.io.JTranscFileStat;
import java.util.Arrays;
public class JTranscAsyncFile {
public String path;
public JTranscAsyncFile(String path) {
this.path = path;
}
static private JTranscAsyncFileSystem fs() {
return JTranscAsyncFileSystem.getInstance();
}
public void getLengthAsync(JTranscAsyncHandler handler) {
fs().getLength(path, handler);
}
public void mkdirAsync(JTranscAsyncHandler handler) {
fs().mkdir(path, handler);
}
public void statAsync(JTranscAsyncHandler handler) {
fs().stat(path, handler);
}
public void openAsync(JTranscFileMode mode, JTranscAsyncHandler handler) {
fs().open(path, mode, handler);
}
public void readAllAsync(final JTranscAsyncHandler handler) {
openAsync(JTranscFileMode.READ, new JTranscAsyncHandler() {
@Override
public void complete(final JTranscAsyncStream asyncStream, Throwable error) {
if (error != null) {
handler.complete(null, error);
} else {
asyncStream.getLengthAsync(new JTranscAsyncHandler() {
@Override
public void complete(Long value, Throwable error) {
if (error != null) {
handler.complete(null, error);
} else {
final byte[] data = new byte[value.intValue()];
asyncStream.readAsync(0L, data, 0, data.length, new JTranscAsyncHandler() {
@Override
public void complete(Integer value, Throwable error) {
if (error != null) {
handler.complete(null, error);
} else {
handler.complete(Arrays.copyOf(data, value), null);
}
}
});
}
}
});
}
}
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy