Ajuda , descompactando arquivos com acentuação

0 respostas
T

Olá amigos , estou em uma empreitada no mundo mobile utilizando PHONEGAP , e instalei um plugin que deszipa arquivos zipados , este plugin está em JAVA, até aqui tudo bém , porém ao descompacta-los o nome dos arquivos que anteriormente tinham "á" acentuação , são convertidos para "?" . Por favor ajudem =/

Obs: já troquei a formatação do projeto para utf-8 no eclipse

O código segue abaixo;
package com.phonegap.plugin.ExtractZipFile;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;

import org.json.JSONArray;
import org.json.JSONException;

import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.api.CordovaPlugin;
import org.apache.cordova.api.PluginResult;

public class ExtractZipFilePlugin extends CordovaPlugin
{
    @Override
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException
    {
        if (action.equals("unzip"))
        {
            String filename = args.getString(0); 
            unzip(filename, callbackContext);
            return true;
        }

        return false;
    }

    private void unzip(String filename, CallbackContext callbackContext)
    {
        File file = new File(filename);
        String[] dirToSplit = filename.split(File.separator);
        String dirToInsert = "";

        for (int i = 0; i < dirToSplit.length - 1; i++)
        {
            dirToInsert += dirToSplit[i] + File.separator;
        }

        BufferedOutputStream dest = null;
        BufferedInputStream is = null;
        ZipEntry entry;
        ZipFile zipfile;

        try
        {
            zipfile = new ZipFile(file);
            Enumeration<? extends ZipEntry> e = zipfile.entries();

            while (e.hasMoreElements()) 
            {
                entry = (ZipEntry)e.nextElement();
                is = new BufferedInputStream(zipfile.getInputStream(entry), 8192);
                int count;
                byte data[] = new byte[102222];
                String fileName = dirToInsert + entry.getName();
                
                byte[] bytes = fileName.getBytes("UTF-8");
                
                filename  = bytes.toString();
                
                File outFile = new File(fileName);
                
                System.out.println(filename);
                
                if (entry.isDirectory()) 
                {
                    outFile.mkdirs();
                } 
                else 
                {
                    FileOutputStream fos = new FileOutputStream(outFile);
                    dest = new BufferedOutputStream(fos, 102222);
                    
                    while ((count = is.read(data, 0, 102222)) != -1)
                    {
                        dest.write(data, 0, count);
                    }

                    dest.flush();
                    dest.close();
                    is.close();
                  }
            }
        }
        catch (ZipException e1)
        {
            callbackContext.error(PluginResult.Status.MALFORMED_URL_EXCEPTION.toString());
            return;
        }
        catch (IOException e1)
        {
            callbackContext.error(PluginResult.Status.IO_EXCEPTION.toString());
            return;
        }

        callbackContext.success(filename);
    }
}
Criado 9 de julho de 2013
Respostas 0
Participantes 1