public T getValueFromSource()

in appactive-java-client/client-channel/src/main/java/io/appactive/channel/file/FileReadDataSource.java [148:184]


    public T getValueFromSource() throws IOException {
        if (file == null) {
            LogUtil.warn("[FileReadDataSource] File is null");
            return null;
        }
        if (!file.exists() || !file.isFile()) {
            LogUtil.warn(
                String.format("[FileReadDataSource] File not exist or is not file: %s", file.getAbsolutePath()));
            return null;
        }
        FileInputStream inputStream = null;
        try {
            inputStream = new FileInputStream(file);
            FileChannel channel = inputStream.getChannel();
            if (channel.size() > buf.length) {
                throw new IllegalStateException(file.getAbsolutePath() + " file size=" + channel.size()
                    + ", is bigger than bufSize=" + buf.length + ". Can't read");
            }
            int len = inputStream.read(buf);
            if (len < 0){
                return null;
            }
            String s = new String(buf, 0, len, charset);
            T convert = converterInterface.convert(s);
            return convert;
        }catch (Exception e){
            LogUtil.warn("FileReadDataSource Exception: {}",e.getCause());
            return null;
        }finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (Exception ignore) {
                }
            }
        }
    }