• Stars
    star
    118
  • Rank 299,923 (Top 6 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 5 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Java Direct IO framework which is very simple to use.

Project

A Java Direct IO framework which is very simple to use.

Add to your project

    <dependency>
        <groupId>moe.cnkirito.kdio</groupId>
        <artifactId>kdio-core</artifactId>
        <version>1.0.0</version>
    </dependency>

Sample

Notice

    // file path should be specific since the different file path determine whether your system support direct io
    public static DirectIOLib directIOLib = DirectIOLib.getLibForPath("/");
    // you should always write into your disk the Integer-Multiple of block size through direct io.
    // in most system, the block size is 4kb
    private static final int BLOCK_SIZE = 4 * 1024;

Usually, only specific linux system support direct io. You should own a linux server.

Write

    private static void write() throws IOException {
        if (DirectIOLib.binit) {
            ByteBuffer byteBuffer = DirectIOUtils.allocateForDirectIO(directIOLib, 4 * BLOCK_SIZE);
            for (int i = 0; i < BLOCK_SIZE; i++) {
                byteBuffer.putInt(i);
            }
            byteBuffer.flip();
            DirectRandomAccessFile directRandomAccessFile = new DirectRandomAccessFile(new File("./database.data"), "rw");
            directRandomAccessFile.write(byteBuffer, 0);
        } else {
            throw new RuntimeException("your system do not support direct io");
        }
    }

Read

    public static void read() throws IOException {
        if (DirectIOLib.binit) {
            ByteBuffer byteBuffer = DirectIOUtils.allocateForDirectIO(directIOLib, 4 * BLOCK_SIZE);
            DirectRandomAccessFile directRandomAccessFile = new DirectRandomAccessFile(new File("./database.data"), "rw");
            directRandomAccessFile.read(byteBuffer, 0);
            byteBuffer.flip();
            for (int i = 0; i < BLOCK_SIZE; i++) {
                System.out.print(byteBuffer.getInt() + " ");
            }
        } else {
            throw new RuntimeException("your system do not support direct io");
        }
    }

Install & Run

mvn clean install -DskipTests

you will get the sample of direct io test: DirectIOTest.jar

deploy it to a linux server and use

java -jar DirectIOTest.jar

you can try it.

License

kdio is under the Apache 2.0 license.

More Repositories

1

oauth2-demo

Re:从零开始的Spring Security Oauth2
Java
1,174
star
2

zuul-gateway-demo

zuul动态路由demo
Java
542
star
3

Java-Interview-Summary

java 程序员面试指南,常用面试题汇总解答
206
star
4

kiritoDB

a high performance key-value engine implementation using JAVA, support get, set, range. (during PolarDB race competition)
Java
204
star
5

dubbo-mesh

alibaba 2018 天池中间件大赛初赛 dubboMesh Rank 15.
Java
128
star
6

queue-race

alibaba 2018 天池中间件大赛复赛百万队列 java 实现
Java
90
star
7

JMH-samples

fork form openjdk
Java
59
star
8

aliyun-cloudnative-race-mq-2021

Java
53
star
9

consistent-hash-algorithm

一致性hash算法
Java
45
star
10

longPolling-demo

Java
40
star
11

spring-security-ipLogin

a tutorial using spring security to verify remoteUser's ip to login in.
Java
35
star
12

sleuth-starter

实现http和motan的链路监控
Java
28
star
13

feign-demo

对于Spring Cloud Feign入门示例的一点思考
Java
19
star
14

2021-tianchi-adb-race

Java
17
star
15

lexburner.github.io

xujingfeng's blog
HTML
10
star
16

decode-benchmark

测试蚂蚁金服的batch decode优化
Java
6
star
17

dubbo-rsocket-demo

demo for dubbo3.x rsocket feature.
Java
5
star
18

dubbo-migration

demo for dubbo project migration
Java
4
star
19

java5-Instrumentation-demo

java拾遗(二)-Instrumentation装配增强
Java
4
star
20

krpc

a RPC framework for test
Java
3
star
21

dubbo-epoll-benchmark

a benchmark for dubbo epoll support
Java
3
star
22

producer-consumer-sample

生产者消费者协调工作例程
Java
2
star
23

dubbo2.7-demo

Dubbo NanJing meetup presentation demo.
Java
1
star
24

multi-channel-benchmark

Java
1
star
25

Dubbo-Sample-TagRouter

A sample of Dubbo for testing TagRouter feature
Java
1
star
26

dubbo-ws-sample

sample for dubbo webService protocol.
Java
1
star