com.itextpdf.io.source.IndependentRandomAccessSource Maven / Gradle / Ivy
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2023 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
*/
package com.itextpdf.io.source;
/**
* A RandomAccessSource that is wraps another RandomAccessSource but does not propagate close(). This is useful when
* passing a RandomAccessSource to a method that would normally close the source.
*/
public class IndependentRandomAccessSource implements IRandomAccessSource {
/**
* The source
*/
private final IRandomAccessSource source;
/**
* Constructs a new IndependentRandomAccessSource object
*
* @param source the source
*/
public IndependentRandomAccessSource(IRandomAccessSource source) {
this.source = source;
}
/**
* {@inheritDoc}
*/
public int get(long position) throws java.io.IOException {
return source.get(position);
}
/**
* {@inheritDoc}
*/
public int get(long position, byte[] bytes, int off, int len) throws java.io.IOException {
return source.get(position, bytes, off, len);
}
/**
* {@inheritDoc}
*/
public long length() {
return source.length();
}
/**
* Does nothing - the underlying source is not closed
*/
public void close() throws java.io.IOException {
// do not close the source
}
}