本文整理汇总了Java中cyclops.control.Try类的典型用法代码示例。如果您正苦于以下问题:Java Try类的具体用法?Java Try怎么用?Java Try使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Try类属于cyclops.control包,在下文中一共展示了Try类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: open
import cyclops.control.Try; //导入依赖的package包/类
@Override
// TODO: Multiple SRT file support
public int open(String path, FileHandleFiller filler) {
if (!path.endsWith(".mkv")) {
return super.open(path, filler);
}
logger.info(path);
Path muxFile = real(path);
List<Path> subFiles = getMatchingSubFiles(muxFile);
if (subFiles.isEmpty()) { // It doesn't need to be muxed, open normally
logger.debug("{} doesn't need muxing", path);
return super.open(path, filler);
}
return Try.withCatch(() -> FileInfo.of(muxFile), Exception.class).map(info -> //
open(path, filler, muxFile, subFiles, info)).recover(this::translateOrThrow).get();
}
示例2: writeToTmpFile
import cyclops.control.Try; //导入依赖的package包/类
private Try<File, Throwable> writeToTmpFile(Object value) {
String fileName = "" + System.currentTimeMillis() + "_" + r.nextLong();
File file = new File(
dir, fileName);
return Try.success(1, Throwable.class)
.map(FluentFunctions.ofChecked(i -> {
FileOutputStream fs = new FileOutputStream(
file);
ObjectOutputStream oos = new ObjectOutputStream(
fs);
oos.writeObject(value);
oos.flush();
oos.close();
return file;
}));
}
示例3: upload
import cyclops.control.Try; //导入依赖的package包/类
@Test
@Ignore
@Repeat(times = 1, threads = 4)
public void upload() {
S3ObjectWriter writerWithoutEncryption = buildWriterWithEncryption(false);
long startNE = System.currentTimeMillis();
Try<UploadResult, Throwable> uploadWithoutEncryption = writerWithoutEncryption.putSync("uploadWithoutEncryption" + r.nextLong(), nullableFile.get());
long endNE = System.currentTimeMillis();
assertTrue(uploadWithoutEncryption.isSuccess());
unencryptedHist.update(endNE - startNE);
S3ObjectWriter writerWithEncryption = buildWriterWithEncryption(true);
long startWE = System.currentTimeMillis();
Try<UploadResult, Throwable> uploadWithEncryption = writerWithEncryption.putSync("uploadWithEncryption" + r.nextLong(), nullableFile.get());
assertTrue(uploadWithEncryption.isSuccess());
long endWE = System.currentTimeMillis();
aes256Hist.update(endWE - startWE);
}
示例4: getattr
import cyclops.control.Try; //导入依赖的package包/类
@Override
public int getattr(String path, StatFiller stat) {
logger.debug(path);
if (!path.endsWith(".mkv")) {
return super.getattr(path, stat);
}
Path muxFile = real(path);
return tryCatchRunnable.apply(() -> {
stat.statWithSize(muxFile, info -> Optional.ofNullable(muxedSizeCache.getIfPresent(info)),
() -> Try.withCatch(() -> extraSizeCache.get(muxFile)).get());
});
}
示例5: testAllErrors
import cyclops.control.Try; //导入依赖的package包/类
protected void testAllErrors(Try.CheckedConsumer<ExpectedResult, Exception> sut)
throws Exception {
List<ExpectedResult> list = list( //
exp(new NoSuchFileException(null), -ErrorCodes.ENOENT()), //
exp(new AccessDeniedException(null), -ErrorCodes.EPERM()), //
exp(new NotDirectoryException(null), -ErrorCodes.ENOTDIR()), //
exp(new NotLinkException(null), -ErrorCodes.EINVAL()), //
exp(new UnsupportedOperationException(), -ErrorCodes.ENOSYS()), //
exp(new IOException(), -ErrorCodes.EIO())); //
list.forEach(expected -> Try.runWithCatch(() -> sut.accept(expected), Exception.class).get());
}
示例6: bothDataWritersUpdated
import cyclops.control.Try; //导入依赖的package包/类
@Test
public void bothDataWritersUpdated() {
writer.saveAndIncrement("hello world");
assertThat(dataWriter1.loadAndGet()
.get(),
equalTo(Try.success("hello world")));
assertThat(dataWriter2.loadAndGet()
.get(),
equalTo(Try.success("hello world")));
}
示例7: emptySaveAndIncrement
import cyclops.control.Try; //导入依赖的package包/类
@Test
public void emptySaveAndIncrement() {
assertThat(empty.saveAndIncrement("hello world")
.get(),
equalTo(Try.success(null)));
}
示例8: testLoadAndGet
import cyclops.control.Try; //导入依赖的package包/类
@Test
public void testLoadAndGet() {
assertThat(eventRecieved.get(), equalTo(0));
dummyMc.setData("hello world");
Future<String> res = writer.loadAndGet();
assertThat(res.get(), equalTo(Try.success("hello world")));
assertThat(dummyMc.loadCalled.get(), equalTo(1));
assertThat(eventRecieved.get(), equalTo(1));
}
示例9: testSaveAndIncrement
import cyclops.control.Try; //导入依赖的package包/类
@Test
public void testSaveAndIncrement() {
assertThat(eventRecieved.get(), equalTo(0));
writer.saveAndIncrement("boo!");
Future<String> res = writer.loadAndGet();
assertThat(res.get(), equalTo(Try.success("boo!")));
assertThat(eventRecieved.get(), equalTo(2));
}
示例10: createObjectRequest
import cyclops.control.Try; //导入依赖的package包/类
private Try<PutObjectRequest, Throwable> createObjectRequest(String key, Object value) {
return writeToTmpFile(value).map(FluentFunctions.ofChecked(f -> {
byte[] ba = FileUtils.readFileToByteArray(f);
InputStream is = new ByteArrayInputStream(
ba);
ObjectMetadata md = createMetadata(ba.length);
PutObjectRequest pr = new PutObjectRequest(
bucket, key, is, md);
return pr;
}));
}
示例11: getAsString
import cyclops.control.Try; //导入依赖的package包/类
/**
*
* Read data from defined S3 bucket with provided key to a String
*
* @param key
* To read
* @return Data as String
*/
public Try<String, Throwable> getAsString(String key) {
return Try.withCatch(() -> ReactiveSeq.fromStream(new BufferedReader(
new InputStreamReader(
readUtils.getInputStream(bucket,
key))).lines())
.join("\n"));
}
示例12: getAsObject
import cyclops.control.Try; //导入依赖的package包/类
public <T> Try<T, Throwable> getAsObject(String key) {
return Try.withCatch(() -> {
ObjectInputStream ois = new ObjectInputStream(
readUtils.getInputStream(bucket, key));
return (T) ois.readObject();
});
}
示例13: put
import cyclops.control.Try; //导入依赖的package包/类
/**
*
* Writes String data to defined S3 bucket with provided key. Calling
* map / flatMap on the returned try instance will catch any exceptions, any
* exceptions thrown will convert a Success to a Failure
*
* This call is blocking.
*
* @param key
* To read
* @return Data as String
*/
public Try<PutObjectResult, Throwable> put(String key, String value) {
return Try.withCatch(() -> {
byte[] bytes = value.getBytes("UTF-8");
ByteArrayInputStream stream = new ByteArrayInputStream(
bytes);
ObjectMetadata md = createMetadata(bytes.length);
return client.putObject(bucket, key, stream, md);
});
}
示例14: createNullableFile
import cyclops.control.Try; //导入依赖的package包/类
private static Optional<byte[]> createNullableFile() {
final File file = new File(
System.getProperty("test.file.full.path"));
Try<byte[], Throwable> loadFileOperation = Try.success(1, Throwable.class)
.map(FluentFunctions.ofChecked(i -> {
return FileUtils.readFileToByteArray(file);
}));
loadFileOperation.onFail(e -> log.error(e.getMessage()));
Optional<byte[]> nFile = loadFileOperation.toOptional();
return nFile;
}
示例15: setupExpectedData
import cyclops.control.Try; //导入依赖的package包/类
private void setupExpectedData(Date lastModTime, String key, String data, long version) {
expectedData = new Data<>(data, lastModTime, versionKey);
versionKey = new VersionedKey(key, version).toJson();
when(reader.getAsString(key)).thenReturn(Try.success(versionKey));
when(reader.getAsObject(versionKey)).thenReturn(Try.success(expectedData));
when(reader.getLastModified(versionKey)).thenReturn(lastModTime);
}