当前位置: 首页>>代码示例>>Java>>正文


Java Try类代码示例

本文整理汇总了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();
}
 
开发者ID:tfiskgul,项目名称:mux2fs,代码行数:17,代码来源:MuxFs.java

示例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;
              }));
}
 
开发者ID:aol,项目名称:micro-server,代码行数:19,代码来源:S3ObjectWriter.java

示例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);
    
    
}
 
开发者ID:aol,项目名称:micro-server,代码行数:21,代码来源:S3UploadSystemTest.java

示例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());
	});
}
 
开发者ID:tfiskgul,项目名称:mux2fs,代码行数:13,代码来源:MuxFs.java

示例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());
}
 
开发者ID:tfiskgul,项目名称:mux2fs,代码行数:12,代码来源:Fixture.java

示例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")));
}
 
开发者ID:aol,项目名称:micro-server,代码行数:11,代码来源:MultiDataWriterTest.java

示例7: emptySaveAndIncrement

import cyclops.control.Try; //导入依赖的package包/类
@Test
public void emptySaveAndIncrement() {

    assertThat(empty.saveAndIncrement("hello world")
                    .get(),
               equalTo(Try.success(null)));
}
 
开发者ID:aol,项目名称:micro-server,代码行数:8,代码来源:MultiDataWriterTest.java

示例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));
}
 
开发者ID:aol,项目名称:micro-server,代码行数:11,代码来源:AsyncDataWriterTest.java

示例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));
}
 
开发者ID:aol,项目名称:micro-server,代码行数:9,代码来源:AsyncDataWriterTest.java

示例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;
        }));
    }
 
开发者ID:aol,项目名称:micro-server,代码行数:15,代码来源:S3ObjectWriter.java

示例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"));

}
 
开发者ID:aol,项目名称:micro-server,代码行数:17,代码来源:S3Reader.java

示例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();
    });

}
 
开发者ID:aol,项目名称:micro-server,代码行数:9,代码来源:S3Reader.java

示例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);

    });

}
 
开发者ID:aol,项目名称:micro-server,代码行数:26,代码来源:S3StringWriter.java

示例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;
}
 
开发者ID:aol,项目名称:micro-server,代码行数:13,代码来源:S3UploadSystemTest.java

示例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);
}
 
开发者ID:aol,项目名称:micro-server,代码行数:8,代码来源:S3ManifestComparatorTest.java


注:本文中的cyclops.control.Try类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。