2
* This file is part of the SUB Commons project.
3
* Visit the websites for more information.
4
* - http://gdz.sub.uni-goettingen.de
6
* Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
8
* Licensed under the Apache License, Version 2.0 (the “License”);
9
* you may not use this file except in compliance with the License.
10
* You may obtain a copy of the License at
12
* http://www.apache.org/licenses/LICENSE-2.0
14
* Unless required by applicable law or agreed to in writing, software
15
* distributed under the License is distributed on an “AS IS” BASIS,
16
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
* See the License for the specific language governing permissions and
18
* limitations under the License.
21
package de.unigoettingen.sub.commons.util.stream;
23
import java.io.BufferedInputStream;
25
import java.io.FileOutputStream;
26
import java.io.IOException;
27
import java.io.InputStream;
31
* The Class SimpleInputStreamSaver provides a simple way to save the contents of an InputSream in a File.
33
public class SimpleInputStreamSaver {
42
* Instantiates a new simple input stream saver.
44
public SimpleInputStreamSaver () {
49
* Instantiates a new simple input stream saver.
51
* @param file the file to the the contents to.
52
* @param is the InputStream to save
54
public SimpleInputStreamSaver (File file, InputStream is) {
60
* Safe the contents of the stream
62
* @throws IOException Signals that an I/O exception has occurred.
64
public void safe () throws IOException {
65
BufferedInputStream bis = new BufferedInputStream(is);
66
FileOutputStream fos = new FileOutputStream(file);
68
int bufSize = 1024 * 8;
69
byte[] bytes = new byte[bufSize];
70
int count = bis.read(bytes);
71
while (count != -1 && count <= bufSize) {
72
fos.write(bytes, 0, count);
73
count = bis.read(bytes);
76
fos.write(bytes, 0, count);
90
public File getFile() {
97
* @param file the new file
99
public void setFile(File file) {
104
* Gets the InputStream.
106
* @return the InputStream.
108
public InputStream getIs() {
113
* Sets the InputStream.
115
* @param is the InputStream.
117
public void setIs(InputStream is) {