Olá pessoal,
tenho um script terceirizado que converte Binário para ASCII no linux perfeitamente, porém, peguei este script e rodei no windows e ele não funciona corretamente, deixa de compilar algumas linhas mas sem acusar erro algum.
Alguem teria uma idéia do que poderia ser?
O script é este:
[code]/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package philips;
// Decompiled by DJ v3.10.10.93 Copyright 2007 Atanas Neshkov Date: 11/6/2008 14:01:38
// Home Page: http://members.fortunecity.com/neshkov/dj.html http://www.neshkov.com/dj.html - Check often for new version!
// Decompiler options: packimports(3)
// Source File Name: PhilipsConverterLinux.java
import java.io.*;
public class PhilipsConverterLinux
{
public static int binaryToAscii(File file, File file1)
throws IOException
{
if(!file.exists())
throw new IOException("Arquivo n\343o encontrado!");
if(!file1.exists())
file1.createNewFile();
int i = 0;
try
{
System.out.println((new StringBuilder()).append("[").append(file.getName()).append("]").toString());
if(file.length() != 0L)
{
String s = "";
char ac[] = getBytesFromFile(file);
System.out.println((new StringBuilder()).append("Convertendo arquivo com ").append(ac.length).append(" bytes").toString());
int j = 128;
FileOutputStream fileoutputstream = new FileOutputStream(file1);
while(j < ac.length && j + 54 < ac.length)
{
boolean flag = false;
if(ac[j + 54] == '\260')
flag = true;
if(ac[j + 32] == '\260')
flag = true;
if(!flag)
while(ac[j] != '\260' && j < ac.length - 54)
{
j++;
System.out.print(".");
}
String s2 = (new StringBuilder()).append(lowerNibble(ac[j++])).append(higherNibble(ac[j])).toString();
String s1 = (new StringBuilder()).append(lowerNibble(ac[j++])).append(higherNibble(ac[j])).toString();
String s3 = lowerNibble(ac[j++]);
if(s3.compareTo("1") == 0 && ac.length - j > 54)
{
String s4 = (new StringBuilder()).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).toString();
String s6 = (new StringBuilder()).append(toHexa(ac[j++])).append(toHexa(ac[j++])).toString();
String s8 = (new StringBuilder()).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).toString();
String s10 = (new StringBuilder()).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).toString();
String s12 = (new StringBuilder()).append(higherNibble(ac[j++])).append(higherNibble(ac[j++])).toString();
String s14 = toHexa(ac[j++]);
String s16 = (new StringBuilder()).append(toHexa(ac[j++])).append(toHexa(ac[j++])).toString();
String s18 = higherNibble(ac[j++]);
String s20 = (new StringBuilder()).append(toHexa(ac[j++])).append(higherNibble(ac[j++])).toString();
String s22 = higherNibble(ac[j++]);
String s24 = higherNibble(ac[j++]);
String s25 = (new StringBuilder()).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).toString();
String s26 = (new StringBuilder()).append("* #").append(s2).append(s1).append(s3).append(s4).append(s6).append(s8).append(s10).append(s12).append(s14).append(s16).append(s18).append(s20).append(s22).append(s24).append(s25).append("\r\n").toString();
fileoutputstream.write(s26.getBytes("ASCII"));
fileoutputstream.flush();
j++;
i++;
} else
if(s3.compareTo("2") == 0)
{
String s5 = "";
for(int k = 0; k < 10; k++)
s5 = (new StringBuilder()).append(s5).append(toHexa(ac[j++])).toString();
String s7 = higherNibble(ac[j++]);
String s9 = higherNibble(ac[j++]);
String s11 = higherNibble(ac[j++]);
String s13 = higherNibble(ac[j++]);
String s15 = (new StringBuilder()).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).toString();
String s17 = (new StringBuilder()).append(toHexa(ac[j++])).append(higherNibble(ac[j++])).toString();
String s19 = (new StringBuilder()).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).toString();
String s21 = (new StringBuilder()).append(toHexa(ac[j++])).append(toHexa(ac[j++])).append(toHexa(ac[j++])).toString();
String s23 = (new StringBuilder()).append("* #").append(s2).append(s1).append(s3).append(s5).append(s7).append(s9).append(s11).append(s13).append(s15).append(s17).append(s19).append(s21).append("\r\n").toString();
fileoutputstream.write(s23.getBytes("ASCII"));
fileoutputstream.flush();
j++;
i++;
} else
{
while(ac[j] != '\260' && j < ac.length - 54)
{
j++;
System.out.print("*");
}
}
}
fileoutputstream.close();
System.out.println((new StringBuilder()).append(" - Bilhetes:").append(i).toString());
}
if(file.length() > 3000L && file.length() > file1.length())
throw new IOException("CHECK: Tamanho deve ser verificado!");
if(file.length() > 3000L && (file.length() - 256L) / 54L > (long)i)
throw new IOException("CHECK: N\372mero de bilhetes deve ser verificado!");
}
catch(Exception exception)
{
exception.printStackTrace();
throw new IOException("Erro de convers\343o!");
}
return i;
}
private static String lowerNibble(char c)
{
String s = Integer.toString(c, 16);
if(s.length() < 2)
s = (new StringBuilder()).append("0").append(s).toString();
return (new StringBuilder()).append("").append(change(s.charAt(1))).toString();
}
private static String higherNibble(char c)
{
String s = Integer.toString(c, 16);
if(s.length() < 2)
s = (new StringBuilder()).append("0").append(s).toString();
return (new StringBuilder()).append("").append(change(s.charAt(0))).toString();
}
private static String toHexa(char c)
{
String s = Integer.toString(c, 16);
if(s.length() < 2)
s = (new StringBuilder()).append("0").append(s).toString();
return (new StringBuilder()).append("").append(change(s.charAt(0))).append(change(s.charAt(1))).toString();
}
private static char change(char c)
{
String s = (new StringBuilder()).append("").append(c).toString();
s = s.toUpperCase();
if(s.compareTo("F") == 0)
return ' ';
if(s.compareTo("A") == 0)
return '*';
else
return c;
}
public static char[] getBytesFromFile(File file)
throws IOException
{
BufferedReader bufferedreader = new BufferedReader(new FileReader(file));
long l = file.length();
int i = (int)(l / 128L);
long l1 = l - (long)i;
char ac[] = new char[(int)l1];
int j = 0;
int k = bufferedreader.read();
checkIn(k);
for(int k1 = 0; k1 < i; k1++)
{
for(int i2 = 0; i2 < 127; i2++)
{
int i1 = bufferedreader.read();
checkIn(i1);
ac[j++] = (char)i1;
}
int j1 = bufferedreader.read();
}
bufferedreader.close();
if(j + 128 < ac.length)
{
System.out.println((new StringBuilder()).append("Offset:").append(j).append(" Length:").append(ac.length).toString());
throw new IOException((new StringBuilder()).append("Could not completely read file ").append(file.getName()).toString());
} else
{
return ac;
}
}
private static void checkIn(int i)
throws IOException
{
if(i == -1)
throw new IOException("ERRO no stream!");
else
return;
}
private PhilipsConverterLinux()
{
}
public static void main(String args[])
{
if(args.length != 2)
{
try
{
//String s = (new StringBuilder()).append("/home/publico/ConverteArquivoLinux/arquivo_binario/").append(args[0]).toString();
//String s = (new StringBuilder()).append(args[0]).toString();
String s = "C:\\java\\philips\\bilv7.u01";
//String s1 = (new StringBuilder()).append("/home/publico/ConverteArquivoLinux/arquivo_texto/").append(args[1]).toString();
// String s1 = (new StringBuilder()).append(args[1]).toString();
String s1 = “C:\java\philips\resultado.u01”;
// System.out.println(args[0]);
// System.out.println(args[1]);
binaryToAscii(new File(s), new File(s1));
}
catch(IOException ioexception)
{
ioexception.printStackTrace();
System.out.println(“N\343o foi poss\355vel ler o arquivo fonte ou escrever o arquivo destino”);
}
} else
{
System.out.println(“Favor informar o arquivo bin\341rio e o arquivo texto.”);
System.exit(0);
}
}
}[/code]
Obrigado