/**
* Copyright 2016 LinkedIn Corp. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/
package com.github.ambry.replication;
import com.github.ambry.store.FindToken;
import com.github.ambry.store.FindTokenFactory;
import java.io.DataInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
public class MockFindTokenFactory implements FindTokenFactory {
@Override
public FindToken getFindToken(DataInputStream stream) throws IOException {
return new MockFindToken(stream);
}
@Override
public FindToken getNewFindToken() {
return new MockFindToken(0, 0);
}
}
class MockFindToken implements FindToken {
int index;
long bytesRead;
public MockFindToken(int index, long bytesRead) {
this.index = index;
this.bytesRead = bytesRead;
}
public MockFindToken(DataInputStream stream) throws IOException {
this.index = stream.readInt();
this.bytesRead = stream.readLong();
}
@Override
public byte[] toBytes() {
ByteBuffer byteBuffer = ByteBuffer.allocate(12);
byteBuffer.putInt(index);
byteBuffer.putLong(bytesRead);
return byteBuffer.array();
}
public int getIndex() {
return index;
}
public long getBytesRead() {
return this.bytesRead;
}
}