|
From: <de...@us...> - 2011-09-23 16:34:42
|
Revision: 6436
http://fudaa.svn.sourceforge.net/fudaa/?rev=6436&view=rev
Author: deniger
Date: 2011-09-23 16:34:35 +0000 (Fri, 23 Sep 2011)
Log Message:
-----------
Modified Paths:
--------------
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/fichiers/NativeNIOHelper.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/NativeBinaryOutputStream.java
===================================================================
--- trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fichiers/NativeBinaryOutputStream.java 2011-09-19 20:43:15 UTC (rev 6435)
+++ trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fichiers/NativeBinaryOutputStream.java 2011-09-23 16:34:35 UTC (rev 6436)
@@ -107,7 +107,7 @@
* @param _int32 l'entier a ecrire sur 4 octets
* @throws IOException
*/
- public void writeInt32(final int _int32) throws IOException {
+ public int writeInt32(final int _int32) throws IOException {
int tmp;
int signCorr;
if (_int32 < 0) {
@@ -124,6 +124,7 @@
buf_[syst_.i2_] = (byte) (tmp - signCorr); // (byte)(tmp>127?tmp-25:tmp);
buf_[syst_.i1_] = (byte) (_int32 % 0x100);
write(buf_);
+ return buf_.length;
}
/**
@@ -148,7 +149,7 @@
* @param _int64 l'entier a ecrire sur 8 octets
* @throws IOException
*/
- public void writeInt64(final long _int64) throws IOException {
+ public int writeInt64(final long _int64) throws IOException {
long tmp;
long signCorr;
if (_int64 < 0) {
@@ -173,33 +174,34 @@
buf_[syst_.l2_] = (byte) (tmp - signCorr); // (byte)(tmp>127?tmp-256:tmp);
buf_[syst_.l1_] = (byte) (_int64 % 0x100L);
write(buf_);
+ return buf_.length;
}
/**
* @param _float32 le float a ecrire sur 4 octets
* @throws IOException
*/
- public void writeFloat32(final float _float32) throws IOException {
+ public int writeFloat32(final float _float32) throws IOException {
// B.M. Java autorise la valeur -0.0 qui perturbe le codage en bytes.
// L'int\xE9r\xEAt de cette valeur \xE9tant tr\xE8s relative, on la remplace par 0.0
float f = _float32;
if (f == -0.0f) {
f = 0.0f;
}
- writeInt32(Float.floatToIntBits(f));
+ return writeInt32(Float.floatToIntBits(f));
}
/**
* @param _float64 le float a ecrire sur 8 octets
* @throws IOException
*/
- public void writeFloat64(final double _float64) throws IOException {
+ public int writeFloat64(final double _float64) throws IOException {
// B.M. Java autorise la valeur -0.0 qui perturbe le codage en bytes.
// L'int\xE9r\xEAt de cette valeur \xE9tant tr\xE8s relative, on la remplace par 0.0
double f = _float64;
if (f == -0.0) {
f = 0.0;
}
- writeInt64(Double.doubleToLongBits(f));
+ return writeInt64(Double.doubleToLongBits(f));
}
}
\ No newline at end of file
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 2011-09-19 20:43:15 UTC (rev 6435)
+++ trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fichiers/NativeBinarySystem.java 2011-09-23 16:34:35 UTC (rev 6436)
@@ -1,22 +1,28 @@
/*
* @creation 27 sept. 06
+ *
* @modification $Date: 2006-09-28 13:39:23 $
+ *
* @license GNU General Public License 2
+ *
* @copyright (c)1998-2001 CETMEF 2 bd Gambetta F-60231 Compiegne
+ *
* @mail de...@fu...
*/
package org.fudaa.dodico.fichiers;
+import java.nio.ByteOrder;
+
/**
* @author fred deniger
* @version $Id: NativeBinarySystem.java,v 1.1 2006-09-28 13:39:23 deniger Exp $
*/
public class NativeBinarySystem {
-
+
protected int l1_, l2_, l3_, l4_, l5_, l6_, l7_, l8_;
protected int i1_, i2_, i3_, i4_;
protected int s1_, s2_;
-
+
private String machineType_;
/**
* L'identifiant pour les machine X86.
@@ -35,15 +41,28 @@
*/
public final static String SPARC_NAME = "SPARC";
- public String getMachineType(){
+ public ByteOrder byteOrder;
+
+ public String getMachineType() {
return machineType_;
}
-
- public final void setMachineType(final String _machine){
+
+ public static final ByteOrder getByteOrder(final String _machine) {
String machine = _machine;
if (machine == null) {
machine = NativeBinarySystem.getLocalMachine();
}
+ if (isX86(machine)) { return ByteOrder.LITTLE_ENDIAN; }
+ return ByteOrder.BIG_ENDIAN;
+
+ }
+
+ public final void setMachineType(final String _machine) {
+ String machine = _machine;
+ if (machine == null) {
+ machine = NativeBinarySystem.getLocalMachine();
+ }
+ byteOrder=getByteOrder(_machine);
if (isX86(machine)) {
machineType_ = X86;
l1_ = 0;
@@ -60,8 +79,7 @@
l6_ = 5;
l7_ = 6;
l8_ = 7;
- }
- else {
+ } else {
machineType_ = SPARC;
l1_ = 7;
l2_ = 6;
@@ -84,38 +102,35 @@
* @param _name le nom SPARC_NAME ou X86_NAME
* @return null si non trouve
*/
- public static String getIdFromName(final String _name){
- if (SPARC_NAME.equals(_name)) {
- return SPARC;
- }
- if (X86_NAME.equals(_name)) {
- return X86;
- }
+ public static String getIdFromName(final String _name) {
+ if (SPARC_NAME.equals(_name)) { return SPARC; }
+ if (X86_NAME.equals(_name)) { return X86; }
return null;
}
/**
* @return le nom de la machine a partir des proprietes systemes
*/
- public static final String getLocalMachine(){
+ public static final String getLocalMachine() {
return System.getProperty("os.arch");
}
/**
* @return l'identifiant correspond a la machine.
*/
- public static final String getLocalMachineId(){
+ public static final String getLocalMachineId() {
return getMachineId(System.getProperty("os.arch"));
}
/**
- * Renvoie a partir de l'identifiant de la machine <code>_desc</code>, l'identifiant
- * correctement g\xE9r\xE9 par cette classe. Si non trouvee, <code>null</code> est retourne. Les
- * variables <code>SPARC</code> et <code>X86</code> sont utilisees.
+ * Renvoie a partir de l'identifiant de la machine <code>_desc</code>, l'identifiant correctement g\xE9r\xE9 par cette
+ * classe. Si non trouvee, <code>null</code> est retourne. Les variables <code>SPARC</code> et <code>X86</code> sont
+ * utilisees.
+ *
* @param _desc la description de la machine
* @return l'identifiant associe
*/
- public static final String getMachineId(final String _desc){
+ public static final String getMachineId(final String _desc) {
if (isX86(_desc)) {
return X86;
} else if (isSparc(_desc)) {
@@ -127,53 +142,42 @@
/**
* Si _id est egalt X86 renvoie X86_NAME et de meme pour sparc.
+ *
* @param _id l'identifiant
* @return le nom a afficher
*/
- public static final String getMachineName(final String _id){
- if (X86.equals(_id)) {
- return X86_NAME;
- }
- if (SPARC.equals(_id)) {
- return SPARC_NAME;
- }
+ public static final String getMachineName(final String _id) {
+ if (X86.equals(_id)) { return X86_NAME; }
+ if (SPARC.equals(_id)) { return SPARC_NAME; }
return null;
}
/**
* @return le nom SPARC_NAME ou X86_NAME de la machine local
*/
- public static final String getLocalMachineName(){
+ public static final String getLocalMachineName() {
return getMachineName(getLocalMachineId());
}
/**
* @param _machine la description de la machine
- * @return true si <code>_machine</code> est du type X86 ( si la chaine finit par
- * <code>"X86"</code>). La variable <code>X86</code> est utilisee.
+ * @return true si <code>_machine</code> est du type X86 ( si la chaine finit par <code>"X86"</code>). La variable
+ * <code>X86</code> est utilisee.
*/
- public static final boolean isX86(final String _machine){
- if (_machine == null) {
- return false;
- }
- if (_machine.endsWith(X86)) {
- return true;
- }
+ public static final boolean isX86(final String _machine) {
+ if (_machine == null) { return false; }
+ if (_machine.endsWith(X86)) { return true; }
return false;
}
/**
* @param _machine la description de la machine
- * @return true, si <code>_machine</code> est un identifiant d'une machine sparc ( si finit par
- * <code>"sparc"</code>). La variable <code>SPARC</code> est utilisee.
+ * @return true, si <code>_machine</code> est un identifiant d'une machine sparc ( si finit par <code>"sparc"</code>).
+ * La variable <code>SPARC</code> est utilisee.
*/
- public static final boolean isSparc(final String _machine){
- if (_machine == null) {
- return false;
- }
- if (_machine.endsWith(SPARC)) {
- return true;
- }
+ public static final boolean isSparc(final String _machine) {
+ if (_machine == null) { return false; }
+ if (_machine.endsWith(SPARC)) { return true; }
return false;
}
@@ -181,8 +185,15 @@
* @param _machine l'identifiant ou la description de la machine
* @return <code>true</code> si <code>_machine</code> est geree par cette classe.
*/
- public static boolean isMachineKnown(final String _machine){
+ public static boolean isMachineKnown(final String _machine) {
return (isX86(_machine) || isSparc(_machine));
}
+ /**
+ * @return the byteOrder
+ */
+ public ByteOrder getByteOrder() {
+ return byteOrder;
+ }
+
}
Modified: trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fichiers/NativeNIOHelper.java
===================================================================
--- trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fichiers/NativeNIOHelper.java 2011-09-19 20:43:15 UTC (rev 6435)
+++ trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fichiers/NativeNIOHelper.java 2011-09-23 16:34:35 UTC (rev 6436)
@@ -106,8 +106,9 @@
return buff4_.getInt();
}
+
public void skipRecord() throws IOException {
- final int toSkip = readSequentialData();
+ int toSkip = readSequentialData();
channel_.position(channel_.position() + 4 + toSkip);
}
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 2011-09-19 20:43:15 UTC (rev 6435)
+++ trunk/framework/dodico-common/src/main/java/org/fudaa/dodico/fortran/FortranBinaryOutputStream.java 2011-09-23 16:34:35 UTC (rev 6436)
@@ -1,24 +1,29 @@
/**
- * @creation 1998-08-19
+ * @creation 1998-08-19
* @modification $Date: 2006-09-19 14:42:29 $
- * @license GNU General Public License 2
- * @copyright (c)1998-2001 CETMEF 2 bd Gambetta F-60231 Compiegne
+ * @license GNU General Public License 2
+ * @copyright (c)1998-2001 CETMEF 2 bd Gambetta F-60231 Compiegne
* @mail de...@fu...
*/
package org.fudaa.dodico.fortran;
+
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.charset.Charset;
import org.fudaa.ctulu.fileformat.FortranInterface;
+import org.fudaa.dodico.fichiers.NativeBinaryOutputStream;
+import org.fudaa.dodico.fichiers.NativeBinarySystem;
-import org.fudaa.dodico.fichiers.NativeBinaryOutputStream;
/**
- * Une classe facilitant l'\xE9criture de fichiers binaires lus par Fortran.
- * ATTENTION les methodes heritees et non red\xE9finies dans cette
- * donneront des r\xE9sultats faux.
- * L'\xE9quivalence d'intructions entre Java et Fortran se fera de la mani\xE8re
- * suivante :<BR><PRE>
+ * Une classe facilitant l'\xE9criture de fichiers binaires lus par Fortran. ATTENTION les methodes heritees et non
+ * red\xE9finies dans cette donneront des r\xE9sultats faux. L'\xE9quivalence d'intructions entre Java et Fortran se fera de la
+ * mani\xE8re suivante :<BR>
+ *
+ * <PRE>
* (en consid\xE9rant i=integer/int, f=real/float, d=double precision/double et
* s=character*()/String)
* 1) Pour un fichier \xE0 acces s\xE9quentiel :
@@ -55,126 +60,147 @@
* ...
* out.close();
* </PRE>
- *
- * @version $Id: FortranBinaryOutputStream.java,v 1.14 2006-09-19 14:42:29 deniger Exp $
- * @author Bertrand Marchand
+ *
+ * @version $Id: FortranBinaryOutputStream.java,v 1.14 2006-09-19 14:42:29 deniger Exp $
+ * @author Bertrand Marchand
*/
-public class FortranBinaryOutputStream
- extends NativeBinaryOutputStream
- implements FortranInterface {
- private NativeBinaryOutputStream bufStream_;
+public class FortranBinaryOutputStream implements FortranInterface {
+ // private NativeBinaryOutputStream bufStream_;
private ByteArrayOutputStream arrayStream_;
private boolean sequential_;
private int recordLength_;
+ Charset charset = Charset.forName("ISO-8859-1");
+ private ByteOrder byteOrder;
+ final OutputStream out;
+
/**
* 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 _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)
- {
+ public FortranBinaryOutputStream(final OutputStream _out, final boolean _sequential) {
this(_out, _sequential, System.getProperty("os.arch"));
}
+
/**
* 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 _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
*/
- public FortranBinaryOutputStream(
- final OutputStream _out,
- final boolean _sequential,
- final String _architectureID)
- {
- super(_out, _architectureID);
- arrayStream_= new ByteArrayOutputStream();
- bufStream_= new NativeBinaryOutputStream(arrayStream_, _architectureID);
- sequential_= _sequential;
- recordLength_= 0;
+ public FortranBinaryOutputStream(final OutputStream _out, final boolean _sequential, final String _architectureID) {
+ this.out = _out;
+ arrayStream_ = new ByteArrayOutputStream();
+ byteOrder = NativeBinarySystem.getByteOrder(_architectureID);
+ 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)
+ * 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)
*/
public void setRecordLength(final int _length) {
- recordLength_= _length;
+ recordLength_ = _length;
}
+
/**
- * Retourne la longueur des enregistrements (pour les fichiers \xE0 acc\xE8s
- * <I>Direct</I>.
+ * Retourne la longueur des enregistrements (pour les fichiers \xE0 acc\xE8s <I>Direct</I>.
+ *
* @return Longueur d'enregistrement en longworld (1 longworld=4 octets)
*/
public int getRecordLength() {
return recordLength_;
}
+
/**
* Ecriture d'un champ chaine de caract\xE8res "<I>character</I>" Fortran.
+ *
* @param _s string correspondant \xE0 la chaine de caract\xE8res
* @throws IOException
*/
public void writeCharacter(final String _s) throws IOException {
- bufStream_.writeBytes(_s);
+ //we encode we a defaut encoding:
+ ByteBuffer encode = charset.encode(_s).order(byteOrder);
+ arrayStream_.write(encode.array());
}
- // public void writeCharacter(char[] _c) {
- // }
- // public void writeCharacter(char _c) {
- // }
+
/**
* Ecriture d'un champ entier "<I>integer</I>" Fortran.
+ *
* @param _i int correspondant au integer
* @throws IOException
*/
public void writeInteger(final int _i) throws IOException {
- bufStream_.writeInt32(_i);
+ arrayStream_.write(integerToByte(_i));
}
+
+ private byte[] integerToByte(final int _i) {
+ ByteBuffer buffer = ByteBuffer.allocate(4).putInt(_i).order(byteOrder);
+ byte[] array = buffer.array();
+ return array;
+ }
+
/**
* Ecriture d'un champ r\xE9el "<I>real</I>" Fortran.
+ *
* @param _f float correspondant au real
* @throws IOException
*/
public void writeReal(final float _f) throws IOException {
- bufStream_.writeFloat32(_f);
+ float f = _f;
+ if (_f == -0.0) {
+ f = 0f;
+ }
+ arrayStream_.write(ByteBuffer.allocate(4).putFloat(f).order(byteOrder).array());
}
+
/**
- * Ecriture d'un champ r\xE9el en double pr\xE9cision "<I>double precision</I>".
- * Fortran
+ * Ecriture d'un champ r\xE9el en double pr\xE9cision "<I>double precision</I>". Fortran
+ *
* @param _d double correspondant au double precision
* @throws IOException
*/
public void writeDoublePrecision(final double _d) throws IOException {
- bufStream_.writeFloat64(_d);
+ double d = _d;
+ if (_d == -0.00) {
+ d = 0;
+ }
+ arrayStream_.write(ByteBuffer.allocate(4).putDouble(d).order(byteOrder).array());
}
+
/**
- * Ecriture des champs de l'enregistrement. L'enregistrement doit etre \xE9crit
- * pour que les champs soient \xE9galement \xE9crits sur le fichiers.
- * Un enregistrement correspond \xE0 une instruction WRITE du Fortran
+ * Ecriture des champs de l'enregistrement. L'enregistrement doit etre \xE9crit pour que les champs soient \xE9galement
+ * \xE9crits sur le fichiers. Un enregistrement correspond \xE0 une instruction WRITE du Fortran
+ *
* @throws IOException
*/
public void writeRecord() throws IOException {
if (sequential_) {
- final int t= arrayStream_.size();
- writeInt32(t);
- arrayStream_.writeTo(this);
- writeInt32(t);
+ final int t = arrayStream_.size();
+ byte[] integerToByte = integerToByte(t);
+ out.write(integerToByte);
+ arrayStream_.writeTo(out);
+ out.write(integerToByte);
} else {
- final byte[] buffer= arrayStream_.toByteArray();
- write(buffer, 0, Math.min(buffer.length, 4 * recordLength_));
- for (int i= buffer.length; i < 4 * recordLength_; i++) {
- write(0);
+ final byte[] buffer = arrayStream_.toByteArray();
+ out.write(buffer, 0, Math.min(buffer.length, 4 * recordLength_));
+ for (int i = buffer.length; i < 4 * recordLength_; i++) {
+ out.write(0);
}
}
arrayStream_.reset();
}
+
/**
* Fermeture du fichier.
*/
public void close() throws IOException {
- super.close();
- arrayStream_.close();
- bufStream_.close();
+ out.close();
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
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.
|