I accept the zip directory from the server with no problems, but the next step I need to unpack it I do it using this method
Decompress d = new Decompress(avatarModelZipFile.toString(), getAvatarPath(context).toString()); d.unzip(); here's a class
public class Decompress { private String _zipFile; private String _location; public Decompress(String zipFile, String location) { _zipFile = zipFile; _location = location; _dirChecker(""); } public void unzip() { try { FileInputStream fin = new FileInputStream(_zipFile); ZipInputStream zin = new ZipInputStream(fin); ZipEntry ze; while ((ze = zin.getNextEntry()) != null) { Log.v("Decompress", "Unzipping " + ze.getName()); if(ze.isDirectory()) { _dirChecker(ze.getName()); } else { FileOutputStream fos = new FileOutputStream(_location + ze.getName()); for (int c = zin.read(); c != -1; c = zin.read()) { ----> Log.e("!!!!!!!!!!!!!!!!!!!!!", "!!!!!!!!!!!!!!!!!"); fos.write(c); } zin.closeEntry(); fos.close(); } } zin.close(); } catch(Exception e) { Log.e("Decompress", "unzip", e); } } private void _dirChecker(String dir) { File f = new File(_location + dir); if(!f.isDirectory()) { f.mkdirs(); } } } and when execution reaches the cycle
for (int c = zin.read(); c != -1; c = zin.read()) then it does not go out of it ... I checked a few other examples and they also implemented zip unpacking in the same way ... Why then my cycle never gets the value c != -1; ?
What am I doing wrong?
One attempt to implement
private void fff(String path) { Log.e("!!!!!!!!!!", "!!!!!!!!!!!! 1"); String SFTPHOST = "host"; int SFTPPORT = 3232; String SFTPUSER = "user"; String SFTPPASS = "mypass"; String SFTPWORKINGDIR = "/dir/work"; Session session = null; Channel channel = null; ChannelSftp channelSftp = null; try { Log.e("!!!!!!!!!!", "!!!!!!!!!!!! 2"); JSch jsch = new JSch(); session = jsch.getSession(SFTPUSER, SFTPHOST, SFTPPORT); session.setPassword(SFTPPASS); java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no"); session.setConfig(config); session.connect(); channel = session.openChannel("sftp"); channel.connect(); channelSftp = (ChannelSftp) channel; channelSftp.cd(SFTPWORKINGDIR); ZipInputStream zipStream = new ZipInputStream(channelSftp.get(path)); zipStream.getNextEntry(); Scanner sc = new Scanner(zipStream); while (sc.hasNextLine()) { Log.e("!!!!!!!!!!", "!!!!!!!!!!!! 3"); System.out.println(sc.nextLine()); } } catch (Exception ex) { ex.printStackTrace(); } finally { if (session != null) { session.disconnect(); } if (channelSftp != null) { channelSftp.disconnect(); } if (channel != null) { channel.disconnect(); } } } But I get this error
[CDS] [DNS] Unable to resolve host "host": No address associated with hostname 06-25 14: 10: 28.217 17128-17608 / com.example.android.camera2basic.demo W / System.err: com.jcraft. jsch.JSchException: java.net.UnknownHostException: Unable to resolve host "host": No address associated with hostname 06-25 14: 10: 28.219 17128-17608 / com.example.android.camera2basic.demo W / System.err: at com.jcraft.jsch.Util.createSocket (Util.java upon49) 06-25 14: 10: 28.219 17128-17608 / com.example.android.camera2basic.demo W / System.err: at com.jcraft.jsch .Session.connect (Session.java:215) 06-25 14: 10: 28.219 17128-17608 / com.example.android.camera2basic.demo W / System.err: at com.jcraft.jsch.Session.connect (Session .java: 183) 06-25 14: 10: 28.219 17128-17608 / com.example.android.camera2basic.demo W / System.err: at com.example.android.camera2basic.tools.serverConnection.GetAvatar.fff (GetAvatar .java: 248) 06-25 14: 10: 28.219 17128-17608 / com.example.android.camera2basic.demo W / System.err: at com.example.android.camera2basic.tools.ser verConnection.GetAvatar.doInBackground (GetAvatar.java:53) 06-25 14: 10: 28.219 17128-17608 / com.example.android.camera2basic.demo W / System.err: at com.example.android.camera2basic.tools. serverConnection.GetAvatar.doInBackground (GetAvatar.java:29)