内存:读入,写出

装饰器模式

  • Component抽象构建接口

  • ConcreteComponent具体的构建对象,实现Component接口,通常就是被装饰的原始对象,就对这个对象添加功能

  • Decorator所有装饰器的抽象父类,需要定义一个与Component接口一致的接口,内部持有一个Component对象,就是持有一个被装饰的对象。

  • ConcreteDecoratorA/ConcreteDecoratorB,实际的装饰器对象,实现具体添加功能。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
val source = RandomAccessFile(sourceFile, "r")
val target = RandomAccessFile(targetFile, "rw)

val sourceChannel = source.channel
val targetChannel = source.channel

val byteBuffer = ByteBuffer.allocate(1024 * 1024)

while(sourceChannel.read(byteBuffer) != -1) {
    byteBuffer.flip()
    targetChannel.write(byteBuffer)
    byteBuffer.clear()
}