private static final int BUFFER = 40960;
public static void jiami (byte[] bytes)
{
for (int i=0;i < bytes.length;i++)
{
bytes[i] = (byte)(bytes[i] + 1);
}
}
public static File jiami (File srcFile) throws IOException
{
if (!srcFile.isFile())
{
throw new IOException("specified file not exist or isnot a file");
}
File dstFile = new File(srcFile.getAbsolutePath() + ".jiami");
dstFile.createNewFile();
byte[] buffer = new byte[BUFFER];
FileInputStream fis = new FileInputStream(srcFile);
FileOutputStream fos = new FileOutputStream(dstFile);
final int sizeInAll = fis.available();
long sizeSum = 0;
int bufferSize = 0;
long startTime = System.currentTimeMillis();
long lastProgress = 0;
while ((bufferSize = fis.read(buffer)) != -1)
{
jiami(buffer);
fos.write(buffer);
fos.flush();
sizeSum += bufferSize;
int progress = (int)(100 * sizeSum / sizeInAll);
if (progress > lastProgress)
{
System.out.println("当前进度 : " + progress + "%");
lastProgress = progress;
}
}
fis.close();
fos.close();
System.out.println("加密完成 用时" + ((System.currentTimeMillis() - startTime)) + "毫秒");
System.out.println("文件大小 " + sizeInAll);
return dstFile;
}
public static void jiemi (byte[] bytes)
{
for (int i=0;i < bytes.length;i++)
{
bytes[i] = (byte)(bytes[i] - 1);
}
}
public static File jiemi (File srcFile) throws IOException
{
if (!srcFile.isFile())
{
throw new IOException("specified file not exist or isnot a file");
}
File dstFile = new File(srcFile.getAbsolutePath() + ".jiemi");
dstFile.createNewFile();
byte[] buffer = new byte[BUFFER];
FileInputStream fis = new FileInputStream(srcFile);
FileOutputStream fos = new FileOutputStream(dstFile);
final long sizeInAll = fis.available();
long sizeSum = 0;
int bufferSize = 0;
long startTime = System.currentTimeMillis();
int lastProgress = 0;
while ((bufferSize = fis.read(buffer)) != -1)
{
jiemi(buffer);
fos.write(buffer);
fos.flush();
sizeSum += bufferSize;
int progress = (int)(100 * sizeSum / sizeInAll);
if (progress > lastProgress)
{
System.out.println("当前进度 : " + progress + "%");
lastProgress = progress;
}
}
fis.close();
fos.close();
System.out.println("解密完成 用时" + ((System.currentTimeMillis() - startTime)) + "毫秒");
System.out.println("文件大小 " + sizeInAll);
return dstFile;
}
public static void main (String[] args) throws IOException
{
File testFile = new File("/sdcard/test");
jiemi(jiami(testFile));
}
public static void jiami (byte[] bytes)
{
for (int i=0;i < bytes.length;i++)
{
bytes[i] = (byte)(bytes[i] + 1);
}
}
public static File jiami (File srcFile) throws IOException
{
if (!srcFile.isFile())
{
throw new IOException("specified file not exist or isnot a file");
}
File dstFile = new File(srcFile.getAbsolutePath() + ".jiami");
dstFile.createNewFile();
byte[] buffer = new byte[BUFFER];
FileInputStream fis = new FileInputStream(srcFile);
FileOutputStream fos = new FileOutputStream(dstFile);
final int sizeInAll = fis.available();
long sizeSum = 0;
int bufferSize = 0;
long startTime = System.currentTimeMillis();
long lastProgress = 0;
while ((bufferSize = fis.read(buffer)) != -1)
{
jiami(buffer);
fos.write(buffer);
fos.flush();
sizeSum += bufferSize;
int progress = (int)(100 * sizeSum / sizeInAll);
if (progress > lastProgress)
{
System.out.println("当前进度 : " + progress + "%");
lastProgress = progress;
}
}
fis.close();
fos.close();
System.out.println("加密完成 用时" + ((System.currentTimeMillis() - startTime)) + "毫秒");
System.out.println("文件大小 " + sizeInAll);
return dstFile;
}
public static void jiemi (byte[] bytes)
{
for (int i=0;i < bytes.length;i++)
{
bytes[i] = (byte)(bytes[i] - 1);
}
}
public static File jiemi (File srcFile) throws IOException
{
if (!srcFile.isFile())
{
throw new IOException("specified file not exist or isnot a file");
}
File dstFile = new File(srcFile.getAbsolutePath() + ".jiemi");
dstFile.createNewFile();
byte[] buffer = new byte[BUFFER];
FileInputStream fis = new FileInputStream(srcFile);
FileOutputStream fos = new FileOutputStream(dstFile);
final long sizeInAll = fis.available();
long sizeSum = 0;
int bufferSize = 0;
long startTime = System.currentTimeMillis();
int lastProgress = 0;
while ((bufferSize = fis.read(buffer)) != -1)
{
jiemi(buffer);
fos.write(buffer);
fos.flush();
sizeSum += bufferSize;
int progress = (int)(100 * sizeSum / sizeInAll);
if (progress > lastProgress)
{
System.out.println("当前进度 : " + progress + "%");
lastProgress = progress;
}
}
fis.close();
fos.close();
System.out.println("解密完成 用时" + ((System.currentTimeMillis() - startTime)) + "毫秒");
System.out.println("文件大小 " + sizeInAll);
return dstFile;
}
public static void main (String[] args) throws IOException
{
File testFile = new File("/sdcard/test");
jiemi(jiami(testFile));
}