package com.aip.gateway.api.aip.utils;

import com.microsoft.informationprotection.IStream;

import java.util.Base64;

public class AipFileStream implements IStream {

    private byte[] fileData;

    public AipFileStream(String fileDataString) {
        this.fileData = Base64.getDecoder().decode(fileDataString);;
    }

    @Override
    public long read(byte[] bytes, long l) {
        int readLength = (int)Math.min(l, fileData.length);
        bytes = new byte[readLength];
        System.arraycopy(fileData, 0, bytes, 0, readLength);
        return readLength;
    }

    @Override
    public long write(byte[] bytes) {
        return 0;
    }

    @Override
    public boolean flush() {
        return true;
    }

    @Override
    public void seek(long l) {

    }

    @Override
    public boolean canRead() {
        return true;
    }

    @Override
    public boolean canWrite() {
        return false;
    }

    @Override
    public long position() {
        return 0;
    }

    @Override
    public long size() {
        return this.fileData.length;
    }

    @Override
    public void size(long l) {

    }
}
