Java Byte Array Encode encode(String prefix, byte[] buf, ZipOutputStream zos, File[] files)

Here you can find the source of encode(String prefix, byte[] buf, ZipOutputStream zos, File[] files)

Description

encode

License

Open Source License

Declaration

private static void encode(String prefix, byte[] buf, ZipOutputStream zos, File[] files) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedInputStream;

import java.io.File;
import java.io.FileInputStream;

import java.io.InputStream;

import java.util.zip.ZipEntry;

import java.util.zip.ZipOutputStream;

public class Main {
    private static void encode(String prefix, byte[] buf, ZipOutputStream zos, File[] files) {
        for (File f : files) {
            try {
                if (f.isDirectory()) {
                    encode(prefix, buf, zos, f.listFiles());
                } else {
                    ZipEntry entry = new ZipEntry(f.getPath().replace(prefix, "").replace('\\', '/'));
                    zos.putNextEntry(entry);
                    try (InputStream is = new BufferedInputStream(new FileInputStream(f))) {
                        for (;;) {
                            int len = is.read(buf);
                            if (len < 0)
                                break;
                            zos.write(buf, 0, len);
                        }//w ww.j a  va 2  s .  com
                    }
                }
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}

Related

  1. encode(byte[] in, int len)
  2. encode(byte[] input)
  3. encode(byte[] message)
  4. encode(byte[] rawData)
  5. encode(byte[] source)
  6. encodeAsUtf8(byte[] bytes)
  7. encodeBitString(byte[] in, OutputStream os)
  8. encodeByteArray(DataOutputStream out, byte[] bytes)
  9. encodeBytes(byte[] source, int off, int len)