|
From: <bma...@us...> - 2013-05-16 21:35:24
|
Revision: 8407
http://sourceforge.net/p/fudaa/svn/8407
Author: bmarchan
Date: 2013-05-16 21:35:21 +0000 (Thu, 16 May 2013)
Log Message:
-----------
Fix : Ecriture/lecture des fichiers binaires en fonction de ByteOrder.nativeOrder() et non plus en fonction du nom de l'architecture.
Modified Paths:
--------------
trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fichiers/NativeBinaryInputStream.java
trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fichiers/NativeBinaryOutputStream.java
trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fichiers/NativeBinarySystem.java
trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fortran/DodicoArraysBinaryFileSaver.java
trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fortran/DodicoDoubleArrayBinaryFileSaver.java
trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fortran/FortranBinaryInputStream.java
trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fortran/FortranBinaryOutputStream.java
Modified: trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fichiers/NativeBinaryInputStream.java
===================================================================
--- trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fichiers/NativeBinaryInputStream.java 2013-05-16 20:24:17 UTC (rev 8406)
+++ trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fichiers/NativeBinaryInputStream.java 2013-05-16 21:35:21 UTC (rev 8407)
@@ -11,10 +11,11 @@
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.ByteOrder;
/**
- * Une classe etendant DataInputStream et permettant de facilement lire des fichiers binaires dependants de la machine
- * (sparc, i386, ...).
+ * Une classe etendant DataInputStream et permettant de facilement lire des fichiers binaires dependants de l'architecture
+ * endianess (LITTLE_ENDIAN ou BIG_ENDIAN).
*
* @version $Id: NativeBinaryInputStream.java,v 1.6 2006-09-28 13:39:11 deniger Exp $
* @author Axel von Arnim
@@ -37,6 +38,7 @@
* @param _bufferLength la taille du buffer
* @param _machine l'identifiant de la machine
* @throws IOException
+ * @deprecated L'identifiant machine ne permet pas d'identifier le byte order natif.
*/
public NativeBinaryInputStream(final InputStream _in, final int _bufferLength, final String _machine)
throws IOException {
@@ -47,6 +49,7 @@
* @param _in le flux support
* @param _machine l'identifiant de la machine
* @throws IOException
+ * @deprecated L'identifiant machine ne permet pas d'identifier le byte order natif.
*/
public NativeBinaryInputStream(final InputStream _in, final String _machine) throws IOException {
this(new BufferedInputStream(_in), _machine);
@@ -56,6 +59,7 @@
* @param _in le flux support
* @param _machine l'identifiant de la machine
* @throws IOException
+ * @deprecated L'identifiant machine ne permet pas d'identifier le byte order natif.
*/
public NativeBinaryInputStream(final BufferedInputStream _in, final String _machine) throws IOException {
in_ = new DataInputStream(_in);
@@ -64,6 +68,34 @@
}
/**
+ * @param _in le flux support
+ * @throws IOException
+ */
+ public NativeBinaryInputStream(final InputStream _in) throws IOException {
+ this(_in, NativeBinarySystem.getNativeByteOrder());
+ }
+
+ /**
+ * @param _in le flux support
+ * @param _byteOrder L'endianess machine.
+ * @throws IOException
+ */
+ public NativeBinaryInputStream(final InputStream _in, ByteOrder _byteOrder) throws IOException {
+ this(new BufferedInputStream(_in),_byteOrder);
+ }
+
+ /**
+ * @param _in le flux support
+ * @param _byteOrder L'endianess machine.
+ * @throws IOException
+ */
+ public NativeBinaryInputStream(final BufferedInputStream _in, ByteOrder _byteOrder) throws IOException {
+ in_ = new DataInputStream(_in);
+ setByteOrder(_byteOrder);
+ buf_ = new byte[8];
+ }
+
+ /**
* Lecture d'un champ chaine de caract\xE8res " <I>character </I>" Fortran.
*
* @param _lgString Longueur de la chaine \xE0 lire
@@ -129,9 +161,26 @@
}
/**
+ * Affecte l'endianess.
+ *
+ * @param _byteOrder L'endianess de l'architecture machine.
+ */
+ public final void setByteOrder(final ByteOrder _byteOrder) {
+ system_.setByteOrder(_byteOrder);
+ }
+
+ /**
+ * @return L'endianess associ\xE9 \xE0 l'arcitecture machine.
+ */
+ public final ByteOrder getByteOrder() {
+ return system_.getByteOrder();
+ }
+
+ /**
* Affecte le type de machine. Par d\xE9faut, le type sparc est utilise.
*
* @param _machine le type de la machine
+ * @deprecated L'identifiant machine ne permet pas d'identifier le byte order natif.
*/
public final void setMachineType(final String _machine) {
system_.setMachineType(_machine);
@@ -139,6 +188,7 @@
/**
* @return l'identifiant de la machine utilisee
+ * @deprecated L'identifiant machine ne permet pas d'identifier le byte order natif.
*/
public String getMachineType() {
return system_.getMachineType();
Modified: trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fichiers/NativeBinaryOutputStream.java
===================================================================
--- trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fichiers/NativeBinaryOutputStream.java 2013-05-16 20:24:17 UTC (rev 8406)
+++ trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fichiers/NativeBinaryOutputStream.java 2013-05-16 21:35:21 UTC (rev 8407)
@@ -10,6 +10,7 @@
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.nio.ByteOrder;
/**
* Une classe etendant DataOutputStream et permettant de facilement ecrire des fichiers binaires. dependants de la
@@ -24,29 +25,39 @@
byte[] buf_;
/**
+ * Contructeur, avec un endianess fonction de l'architecture machine.
* @param _out le flux suppor
- * @param _machine la description ou l'id de la machine
* @see NativeBinarySystem#getLocalMachine()
*/
- public NativeBinaryOutputStream(final OutputStream _out, final String _machine) {
+ public NativeBinaryOutputStream(final OutputStream _out) {
+ this(_out, NativeBinarySystem.getNativeByteOrder());
+ }
+
+ /**
+ * @param _out le flux suppor
+ * @param _byteOrder l'endianess de la machine
+ * @see NativeBinarySystem#getLocalMachine()
+ */
+ public NativeBinaryOutputStream(final OutputStream _out, final ByteOrder _byteOrder) {
super(_out);
buf_ = null;
- setMachineType(_machine);
+ setByteOrder(_byteOrder);
}
/**
- * @param _machine le type de la machine (X86 ou sparc)
- * @see NativeBinarySystem#getLocalMachine()
+ * Affecte l'endianess.
+ *
+ * @param _byteOrder L'endianess de l'architecture machine.
*/
- public final void setMachineType(final String _machine) {
- syst_.setMachineType(_machine);
+ public final void setByteOrder(final ByteOrder _byteOrder) {
+ syst_.setByteOrder(_byteOrder);
}
/**
- * @return le type de machine utilise
+ * @return L'endianess associ\xE9 \xE0 l'arcitecture machine.
*/
- public String getMachineType() {
- return syst_.getMachineType();
+ public final ByteOrder getByteOrder() {
+ return syst_.getByteOrder();
}
/**
Modified: trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fichiers/NativeBinarySystem.java
===================================================================
--- trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fichiers/NativeBinarySystem.java 2013-05-16 20:24:17 UTC (rev 8406)
+++ trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fichiers/NativeBinarySystem.java 2013-05-16 21:35:21 UTC (rev 8407)
@@ -14,6 +14,8 @@
import java.nio.ByteOrder;
/**
+ * Classe de d\xE9finition des parametres de d\xE9codage des binaires en endianess.
+ *
* @author fred deniger
* @version $Id: NativeBinarySystem.java,v 1.1 2006-09-28 13:39:23 deniger Exp $
*/
@@ -47,6 +49,9 @@
return machineType_;
}
+ /**
+ * @deprecated Ne plus utiliser, cette m\xE9thode est erronn\xE9e.
+ */
public static final ByteOrder getByteOrder(final String _machine) {
String machine = _machine;
if (machine == null) {
@@ -57,13 +62,23 @@
}
- public final void setMachineType(final String _machine) {
- String machine = _machine;
- if (machine == null) {
- machine = NativeBinarySystem.getLocalMachine();
- }
- byteOrder=getByteOrder(_machine);
- if (isX86(machine)) {
+ /**
+ * @return Le type d'encodage natif des octets, suivant l'architecture de la machine
+ */
+ public static ByteOrder getNativeByteOrder() {
+ return ByteOrder.nativeOrder();
+ }
+
+ /**
+ * Definit l'ordre des bytes pour donnees binaires (little_endian ou big_endian).
+ * @param _byteOrder L'ordre des bytes
+ */
+ public final void setByteOrder(ByteOrder _byteOrder) {
+ byteOrder=_byteOrder;
+
+ if (ByteOrder.LITTLE_ENDIAN.equals(_byteOrder)) {
+ // B.M. Cette bijection entre LITTLE_ENDIAN et X86 est erron\xE9e, mais est historique.
+ // On la conserve pour la compatibilit\xE9 des programmes.
machineType_ = X86;
l1_ = 0;
i1_ = 0;
@@ -80,6 +95,8 @@
l7_ = 6;
l8_ = 7;
} else {
+ // B.M. Cette bijection entre BIG_ENDIAN et SPARC est erron\xE9e, mais est historique.
+ // On la conserve pour la compatibilit\xE9 des programmes.
machineType_ = SPARC;
l1_ = 7;
l2_ = 6;
@@ -97,6 +114,17 @@
s2_ = 0;
}
}
+
+ /**
+ * @deprecated Ne plus utiliser, cette m\xE9thode est erron\xE9e. Utiliser uniquement {@link #setByteOrder(ByteOrder)}
+ */
+ public final void setMachineType(final String _machine) {
+ String machine = _machine;
+ if (machine == null) {
+ machine = NativeBinarySystem.getLocalMachine();
+ }
+ setByteOrder(getByteOrder(_machine));
+ }
/**
* @param _name le nom SPARC_NAME ou X86_NAME
Modified: trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fortran/DodicoArraysBinaryFileSaver.java
===================================================================
--- trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fortran/DodicoArraysBinaryFileSaver.java 2013-05-16 20:24:17 UTC (rev 8406)
+++ trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fortran/DodicoArraysBinaryFileSaver.java 2013-05-16 21:35:21 UTC (rev 8407)
@@ -1,19 +1,19 @@
package org.fudaa.dodico.fortran;
-import com.memoire.fu.FuEmptyArrays;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileOutputStream;
-
-import org.fudaa.ctulu.fileformat.FortranLib;
-import org.fudaa.dodico.fichiers.NativeBinarySystem;
-
-import com.memoire.fu.FuLog;
-import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.ByteOrder;
+
import org.fudaa.ctulu.CtuluLibArray;
import org.fudaa.ctulu.CtuluLibFile;
+import org.fudaa.ctulu.fileformat.FortranLib;
+import com.memoire.fu.FuEmptyArrays;
+import com.memoire.fu.FuLog;
+
/**
* Permet d'\xE9crire facilement des tableaux d'entier, bool\xE9ens dans un fichier binaire.
*
@@ -56,7 +56,8 @@
FortranBinaryOutputStream output = null;
boolean ok = true;
try {
- output = new FortranBinaryOutputStream(file, true, NativeBinarySystem.X86);
+ // FIXME B.M. Force a little endian pour correspondre anciennement a X86
+ output = new FortranBinaryOutputStream(file, true, ByteOrder.LITTLE_ENDIAN);
int nbValues = in.length;
output.writeInteger(nbValues);
output.writeRecord();
@@ -164,7 +165,8 @@
int[][] mapOfValues = null;
try {
try {
- input = new FortranBinaryInputStream(in, true, NativeBinarySystem.X86);
+ // FIXME B.M. Force a little endian pour correspondre anciennement a X86
+ input = new FortranBinaryInputStream(in, true, ByteOrder.LITTLE_ENDIAN);
input.readRecord();
int nbValues = input.readInteger();
if (nbValues >= 0) {
@@ -206,7 +208,8 @@
FortranBinaryInputStream input = null;
try {
try {
- input = new FortranBinaryInputStream(in, true, NativeBinarySystem.X86);
+ // FIXME B.M. Force a little endian pour correspondre anciennement a X86
+ input = new FortranBinaryInputStream(in, true, ByteOrder.LITTLE_ENDIAN);
input.readRecord();
int nbValues = input.readInteger();
input.readRecord();
@@ -255,7 +258,8 @@
FortranBinaryOutputStream output = null;
boolean ok = true;
try {
- output = new FortranBinaryOutputStream(out, true, NativeBinarySystem.X86);
+ // FIXME B.M. Force a little endian pour correspondre anciennement a X86
+ output = new FortranBinaryOutputStream(out, true, ByteOrder.LITTLE_ENDIAN);
int nbValues = mapOfValues.length;
output.writeInteger(nbValues);
output.writeRecord();
Modified: trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fortran/DodicoDoubleArrayBinaryFileSaver.java
===================================================================
--- trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fortran/DodicoDoubleArrayBinaryFileSaver.java 2013-05-16 20:24:17 UTC (rev 8406)
+++ trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fortran/DodicoDoubleArrayBinaryFileSaver.java 2013-05-16 21:35:21 UTC (rev 8407)
@@ -4,12 +4,12 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
+import java.nio.ByteOrder;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.fudaa.ctulu.fileformat.FortranLib;
-import org.fudaa.dodico.fichiers.NativeBinarySystem;
import com.memoire.fu.FuLog;
@@ -30,7 +30,8 @@
FortranBinaryInputStream input = null;
try {
try {
- input = new FortranBinaryInputStream(new FileInputStream(destFile), true, NativeBinarySystem.X86);
+ // FIXME B.M. Force a little endian pour correspondre anciennement a X86
+ input = new FortranBinaryInputStream(new FileInputStream(destFile), true, ByteOrder.LITTLE_ENDIAN);
while (true) {
input.readRecord();
int readInteger = input.readInteger();
@@ -59,7 +60,8 @@
FortranBinaryOutputStream output = null;
boolean ok = true;
try {
- output = new FortranBinaryOutputStream(new FileOutputStream(destFile), true, NativeBinarySystem.X86);
+ // FIXME B.M. Force a little endian pour correspondre anciennement a X86
+ output = new FortranBinaryOutputStream(new FileOutputStream(destFile), true, ByteOrder.LITTLE_ENDIAN);
for (Entry<String, double[]> entry : mapOfValues.entrySet()) {
String key = entry.getKey();
if (key.isEmpty()) {
Modified: trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fortran/FortranBinaryInputStream.java
===================================================================
--- trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fortran/FortranBinaryInputStream.java 2013-05-16 20:24:17 UTC (rev 8406)
+++ trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fortran/FortranBinaryInputStream.java 2013-05-16 21:35:21 UTC (rev 8407)
@@ -10,10 +10,12 @@
import java.io.IOException;
import java.io.InputStream;
+import java.nio.ByteOrder;
import org.fudaa.ctulu.fileformat.FortranInterface;
import org.fudaa.dodico.fichiers.NativeBinaryInputStream;
+import org.fudaa.dodico.fichiers.NativeBinarySystem;
/**
* Une classe facilitant la lecture de fichiers binaires \xE9crits par Fortran Utilise la classe NativeBinaryInputStream
@@ -87,7 +89,7 @@
* @throws IOException
*/
public FortranBinaryInputStream(final InputStream _in, final boolean _sequential) throws IOException {
- this(_in, _sequential, System.getProperty("os.arch"));
+ this(_in, _sequential, NativeBinarySystem.getNativeByteOrder());
}
/**
@@ -101,8 +103,8 @@
* @see org.fudaa.dodico.fichiers.NativeBinaryInputStream
* @throws IOException
*/
- public FortranBinaryInputStream(final InputStream _in, final boolean _sequential, final String _architectureID) throws IOException {
- super(_in, _architectureID);
+ public FortranBinaryInputStream(final InputStream _in, final boolean _sequential, final ByteOrder _byteOrder) throws IOException {
+ super(_in, _byteOrder);
sequential_ = _sequential;
recordLength_ = 0;
nextPos_ = 0;
Modified: trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fortran/FortranBinaryOutputStream.java
===================================================================
--- trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fortran/FortranBinaryOutputStream.java 2013-05-16 20:24:17 UTC (rev 8406)
+++ trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fortran/FortranBinaryOutputStream.java 2013-05-16 21:35:21 UTC (rev 8407)
@@ -15,7 +15,6 @@
import java.nio.charset.Charset;
import org.fudaa.ctulu.fileformat.FortranInterface;
-import org.fudaa.dodico.fichiers.NativeBinaryOutputStream;
import org.fudaa.dodico.fichiers.NativeBinarySystem;
/**
@@ -80,7 +79,7 @@
* @param _sequential <B>true</B> le fichier est binaire \xE0 acc\xE8s <I>Sequential</I>. <B>false</B> le fichier est binaire \xE0 acc\xE8s <I>Direct</I>
*/
public FortranBinaryOutputStream(final OutputStream _out, final boolean _sequential) {
- this(_out, _sequential, System.getProperty("os.arch"));
+ this(_out, _sequential, NativeBinarySystem.getNativeByteOrder());
}
/**
@@ -89,6 +88,7 @@
* @param _out OutputStream
* @param _sequential <B>true</B> le fichier est binaire \xE0 acc\xE8s <I>Sequential</I>. <B>false</B> le fichier est binaire \xE0 acc\xE8s <I>Direct</I>
* @param _architectureID l'architecture demandee
+ * @deprecated L'identifiant machine ne permet pas d'identifier le byte order natif.
*/
public FortranBinaryOutputStream(final OutputStream _out, final boolean _sequential, final String _architectureID) {
this.out = _out;
@@ -99,6 +99,21 @@
}
/**
+ * Cr\xE9ation en pr\xE9cisant si le fichier binaire est \xE0 access s\xE9quentiel ou non.
+ *
+ * @param _out OutputStream
+ * @param _sequential <B>true</B> le fichier est binaire \xE0 acc\xE8s <I>Sequential</I>. <B>false</B> le fichier est binaire \xE0 acc\xE8s <I>Direct</I>
+ * @param _byteOrder l'endianess demandee
+ */
+ public FortranBinaryOutputStream(final OutputStream _out, final boolean _sequential, final ByteOrder _byteOrder) {
+ this.out = _out;
+ arrayStream_ = new ByteArrayOutputStream();
+ byteOrder = _byteOrder;
+ sequential_ = _sequential;
+ recordLength_ = 0;
+ }
+
+ /**
* Affectation de la longueur des enregistrements (pour les fichiers \xE0 acc\xE8s <I>Direct</I>).
*
* @param _length Longueur d'enregistrement en longworld (1 longworld=4 octets)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|