XxBryantD
June 21st, 2010, 19:15
public String name;
public String dir;
public void downloadcache(String url, String name1, String dir1, String type)
{
dir = dir1;
name = name1;
try
{
URLConnection connection = (new URL(url)).openConnection();
String f[] = url.split("/");
File file = new File(f[f.length - 1]);
int length = connection.getContentLength();
InputStream instream = connection.getInputStream();
try{new File(signlink.findcachedir()+dir).mkdir();}catch(E xception e){}
FileOutputStream outstream = new FileOutputStream(signlink.findcachedir()+dir+file) ;
int size = 0;
int copy;
byte[] buffer = new byte[4096];
while((copy = instream.read(buffer)) != -1)
{
outstream.write(buffer, 0, copy);
size+= copy;
int percentage = (int)(((double)size / (double)length) * 100D);
method13(percentage, (byte)4, "Downloading Cache - "+percentage+"%");
}
if(length != size)
{
instream.close();
outstream.close();
} else
{
method13(5, (byte)4, "Unpacking files...");
instream.close();
outstream.close();
unZipFile();
deleteFile();
method13(10, (byte)4, "Unpacking was complete");
}
}
catch(Exception e)
{
System.err.println("Error connecting to server.");
e.printStackTrace();
}
}
public void writeStream(InputStream In, OutputStream Out) throws IOException
{
byte Buffer[] = new byte[4096];
int Len;
while((Len = In.read(Buffer)) >= 0)
{
Out.write(Buffer, 0, Len);
}
In.close();
Out.close();
}
public void unZipFile()
{
try
{
ZipFile ZipFile = new ZipFile(signlink.findcachedir()+dir+name);
for(Enumeration Entries = ZipFile.entries(); Entries.hasMoreElements();)
{
ZipEntry Entry = (ZipEntry)Entries.nextElement();
if(Entry.isDirectory())
{
(new File(signlink.findcachedir()+dir+Entry.getName())) .mkdir();
} else
{
writeStream(ZipFile.getInputStream(Entry), new BufferedOutputStream(new FileOutputStream(signlink.findcachedir()+dir+Entry .getName())));
}
}
ZipFile.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void deleteFile()
{
try
{
File file = new File(signlink.findcachedir()+dir+name);
file.delete();
}
catch(Exception e)
{
e.printStackTrace();
}
}{
public String dir;
public void downloadcache(String url, String name1, String dir1, String type)
{
dir = dir1;
name = name1;
try
{
URLConnection connection = (new URL(url)).openConnection();
String f[] = url.split("/");
File file = new File(f[f.length - 1]);
int length = connection.getContentLength();
InputStream instream = connection.getInputStream();
try{new File(signlink.findcachedir()+dir).mkdir();}catch(E xception e){}
FileOutputStream outstream = new FileOutputStream(signlink.findcachedir()+dir+file) ;
int size = 0;
int copy;
byte[] buffer = new byte[4096];
while((copy = instream.read(buffer)) != -1)
{
outstream.write(buffer, 0, copy);
size+= copy;
int percentage = (int)(((double)size / (double)length) * 100D);
method13(percentage, (byte)4, "Downloading Cache - "+percentage+"%");
}
if(length != size)
{
instream.close();
outstream.close();
} else
{
method13(5, (byte)4, "Unpacking files...");
instream.close();
outstream.close();
unZipFile();
deleteFile();
method13(10, (byte)4, "Unpacking was complete");
}
}
catch(Exception e)
{
System.err.println("Error connecting to server.");
e.printStackTrace();
}
}
public void writeStream(InputStream In, OutputStream Out) throws IOException
{
byte Buffer[] = new byte[4096];
int Len;
while((Len = In.read(Buffer)) >= 0)
{
Out.write(Buffer, 0, Len);
}
In.close();
Out.close();
}
public void unZipFile()
{
try
{
ZipFile ZipFile = new ZipFile(signlink.findcachedir()+dir+name);
for(Enumeration Entries = ZipFile.entries(); Entries.hasMoreElements();)
{
ZipEntry Entry = (ZipEntry)Entries.nextElement();
if(Entry.isDirectory())
{
(new File(signlink.findcachedir()+dir+Entry.getName())) .mkdir();
} else
{
writeStream(ZipFile.getInputStream(Entry), new BufferedOutputStream(new FileOutputStream(signlink.findcachedir()+dir+Entry .getName())));
}
}
ZipFile.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void deleteFile()
{
try
{
File file = new File(signlink.findcachedir()+dir+name);
file.delete();
}
catch(Exception e)
{
e.printStackTrace();
}
}{