2 * Copyright 2017 CMCC Technologies Co., Ltd
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.vfc.nfvo.emsdriver.commons.utils;
19 import java.util.zip.GZIPInputStream;
27 public void unCompress(String gzFileName, String toFile)
29 GZIPInputStream gzIn = null;
30 FileOutputStream fileOutput = null;
31 FileInputStream gzInput = new FileInputStream(gzFileName);
33 gzIn = new GZIPInputStream(gzInput);
34 File tofile = new File(toFile);
36 fileOutput = new FileOutputStream(tofile, false);
38 moveBytes(gzIn, fileOutput, -1, -1, 1024);
43 if (fileOutput != null) {
52 private void enable(File tofile) throws IOException {
53 if (!tofile.exists()) {
54 String parentPath = tofile.getParent();
55 if (parentPath != null)
56 new File(parentPath).mkdirs();
57 tofile.createNewFile();
62 public long moveBytes(InputStream input, OutputStream output, long off, long len, int bufsize)
68 byte[] buf = new byte[bufsize];
71 if (len > 0 && (len - totalNum) <= 0)
74 else if (len > 0 && bufsize > (len - totalNum))
75 bufsize = (int) (len - totalNum);
77 int readNum = input.read(buf, 0, bufsize);
81 output.write(buf, 0, readNum);