Search in sources :

Example 1 with DefaultControllableFile

use of com.ctrip.xpipe.utils.DefaultControllableFile in project x-pipe by ctripcorp.

the class ReferenceFileChannelTest method beforeReferenceFileChannelTest.

@Before
public void beforeReferenceFileChannelTest() throws FileNotFoundException, IOException {
    String file = getTestFileDir() + "/" + getTestName();
    try (FileOutputStream ous = new FileOutputStream(new File(file))) {
        ous.write(randomString(totalFileLen).getBytes());
    }
    referenceFileChannel = new ReferenceFileChannel(new DefaultControllableFile(file));
}
Also used : DefaultControllableFile(com.ctrip.xpipe.utils.DefaultControllableFile) FileOutputStream(java.io.FileOutputStream) DefaultControllableFile(com.ctrip.xpipe.utils.DefaultControllableFile) File(java.io.File) Before(org.junit.Before)

Example 2 with DefaultControllableFile

use of com.ctrip.xpipe.utils.DefaultControllableFile in project x-pipe by ctripcorp.

the class DefaultRdbStore method createControllableFile.

private ControllableFile createControllableFile() throws IOException {
    if (eofType instanceof LenEofType) {
        return new DefaultControllableFile(file);
    } else if (eofType instanceof EofMarkType) {
        return new SizeControllableFile(file, new FileSize() {

            @Override
            public long getSize(LongSupplier realSizeProvider) {
                long realSize = 0;
                synchronized (truncateLock) {
                    // truncate may make size wrong
                    realSize = realSizeProvider.getAsLong();
                }
                if (status.get() == Status.Writing) {
                    long ret = realSize - ((EofMarkType) eofType).getTag().length();
                    logger.debug("[getSize][writing]{}, {}", DefaultRdbStore.this, ret);
                    return ret < 0 ? 0 : ret;
                }
                return realSize;
            }
        });
    } else {
        throw new IllegalStateException("unknown eoftype:" + eofType.getClass() + "," + eofType);
    }
}
Also used : DefaultControllableFile(com.ctrip.xpipe.utils.DefaultControllableFile) SizeControllableFile(com.ctrip.xpipe.utils.SizeControllableFile) EofMarkType(com.ctrip.xpipe.redis.core.protocal.protocal.EofMarkType) LenEofType(com.ctrip.xpipe.redis.core.protocal.protocal.LenEofType) LongSupplier(java.util.function.LongSupplier) FileSize(com.ctrip.xpipe.api.utils.FileSize)

Aggregations

DefaultControllableFile (com.ctrip.xpipe.utils.DefaultControllableFile)2 FileSize (com.ctrip.xpipe.api.utils.FileSize)1 EofMarkType (com.ctrip.xpipe.redis.core.protocal.protocal.EofMarkType)1 LenEofType (com.ctrip.xpipe.redis.core.protocal.protocal.LenEofType)1 SizeControllableFile (com.ctrip.xpipe.utils.SizeControllableFile)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 LongSupplier (java.util.function.LongSupplier)1 Before (org.junit.Before)1