giovedì 30 giugno 2011

Directory e file temporanei in java

Directory temporanea

System.getProperty("java.io.tmpdir")

File temporanei
File temp = File.createTempFile("real",".howto"); temp.deleteOnExit();

String tempdir = System.getProperty("java.io.tmpdir");
if ( !(tempdir.endsWith("/") || tempdir.endsWith("\\")) )
tempdir = tempdir + System.getProperty("file.separator");

mercoledì 29 giugno 2011

Conversioni di tipi in java

Da double a String

public class
ConvertDoubleToString {
public static void main(String[] args) {
double aDouble = 0.11;
String aString = Double.toString(aDouble);
}
}

Da String a double

public class ConvertStringToDouble {
public static void main(String[] args) {
String aString = "78";
double aDouble = Double.parseDouble(aString);

System.out.println(aDouble);
}
}

Da String a int

String colorChoosed_s = this.prop.getProperty("colorChoosed");
return Integer.parseInt(colorChoosed_s);


Da int a String

int fileFormat= 1;
return Integer.toString(fileFormat)


Da String a boolean

String twainInterfaceEnable_s = this.prop.getProperty("twainInterfaceEnable");
return Boolean.parseBoolean(twainInterfaceEnable_s);


Da boolean a String

boolean
twainInterfaceEnable = false;
return Boolean.toString(twainInterfaceEnable)


lunedì 27 giugno 2011

Serializzazione/deserealizzazione Oggetti Exception con ULC

Lato Client
public void printMessageDialog(IOException exception) {
ByteArrayOutputStream os;
ObjectOutputStream oos;
try {
os = new ByteArrayOutputStream();
oos = new ObjectOutputStream(os);
oos.writeObject(exception);
invokeULC("printMessageDialog", new Object[] { os.toByteArray() });
oos.close();
} catch (FileNotFoundException e) {
logger.error("Unable to send message to server", e);
} catch (IOException e) {
logger.error("Unable to send message to server", e);
}
}


Lato Server


public void printMessageDialog(byte[] bytes) {
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
ObjectInputStream ois;
try {
ois = new ObjectInputStream(bis);
IOException e = (IOException) ois.readObject();
MessageDialogs.error(owner, "Errore nella creazione del file", e.getMessage(), e)
.show();
} catch (IOException e) {
logger.error("Unable to deserialize message object", e);
} catch (ClassNotFoundException e) {
logger.error("Unable to deserialize message object", e);
}
}