Skip to content

Commit

Permalink
imp. isBinary
Browse files Browse the repository at this point in the history
  • Loading branch information
yannrichet committed Feb 5, 2021
1 parent 114c955 commit 01441fc
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 7 deletions.
29 changes: 27 additions & 2 deletions src/main/java/org/funz/util/Disk.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.funz.Protocol;
import java.nio.charset.Charset;

public class Disk {

Expand Down Expand Up @@ -89,6 +90,9 @@ protected static boolean isStringChar(char ch) {
}
switch (ch) {
case ' ':
case '\t':
case '\r':
case '\n':
case '/':
case '+':
case '*':
Expand Down Expand Up @@ -123,24 +127,45 @@ protected static boolean isStringChar(char ch) {
case '\\':
return true;
}
//System.out.println(""+ch+"");
return false;
}

public static boolean isBinary(File f) {
for (Charset cs: new Charset[]{Charset.forName("UTF-8"),Charset.forName("ISO-8859-1"),Charset.forName("ISO-8859-15")}) {
// Consider as binary if no charset get it as ASCII...
if (!isBinary(f, cs)) return false;
}
return true;
}

public static boolean isBinary(File f, Charset inputCharset) {
boolean isbin = false;
java.io.InputStream in = null;

try {
in = new FileInputStream(f);
BufferedReader r = new BufferedReader(new InputStreamReader(in));
BufferedReader r = new BufferedReader(new InputStreamReader(in, inputCharset));

int sample = (int) Math.min(255, f.length());
int sample = (int) Math.min(1024, f.length());

char[] cc = new char[sample]; //do a peek
r.read(cc, 0, sample);

double prob_bin = 0;

// int word_size = 10; // will consider word as binary if >50% chars are binary
// for (int i = 0; i < cc.length-word_size; i=i+word_size) {
// double bins = 0;
// for (int j=0; j<word_size; j++) {
// if (!isStringChar((char) cc[i+j])) bins++;
// }
// if (bins/word_size > 0.5) {
// String b = ">";
// for (int j=0; j<word_size; j++) b=b+" "+(int)cc[i+j];
// System.err.println(b+"<");
// }
// }
for (int i = 0; i < cc.length; i++) {
char j = (char) cc[i];
if (!isStringChar(j)) {
Expand Down
18 changes: 13 additions & 5 deletions src/test/java/org/funz/DiskTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,26 @@ public void testlistRecursiveFiles() {
@Test
public void testIsBinary() {
File java_src = new File("src/main/java/org/funz/util/Disk.java");
assert !Disk.isBinary(java_src) : "bad binary inference";
System.err.println(java_src);
assert !Disk.isBinary(java_src) : "bad binary inference: "+java_src;
File java_class = new File("build/org/funz/util/Disk.class");
assert Disk.isBinary(java_class) : "bad binary inference";
System.err.println(java_class);
assert Disk.isBinary(java_class) : "bad binary inference: "+java_class;
File R_src = new File("src/test/resources/branin.R");
assert !Disk.isBinary(R_src) : "bad binary inference";
System.err.println(R_src);
assert !Disk.isBinary(R_src) : "bad binary inference: "+R_src;
File castem_src = new File("src/test/resources/out.txt");
System.err.println(castem_src);
assert !Disk.isBinary(castem_src) : "bad binary inference: "+castem_src;

if (OS.isFamilyWindows()) {
File cmd = new File("C:\\Windows\\system32\\cmd.exe");
assert Disk.isBinary(cmd) : "bad binary inference";
System.err.println(cmd);
assert Disk.isBinary(cmd) : "bad binary inference: "+cmd;
} else {
File bash = new File("/bin/bash");
assert Disk.isBinary(bash) : "bad binary inference";
System.err.println(bash);
assert Disk.isBinary(bash) : "bad binary inference: "+bash;
}
}
}
105 changes: 105 additions & 0 deletions src/test/resources/out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
SBATCH: -p seq -n 1 -t 00-01:00:00
0:00
Exit code: 0
/12
________________________________________________________________________


Documentation Generale sur Cast3M :
http://www-cast3m.cea.fr/index.php?xml=maj2011

Nouveautes de Cast3M 2016 :
http://www-cast3m.cea.fr/html/ClubCast3m/club2016/
Club_Cast3m_2016_Millard.pdf

________________________________________________________________________

$ * *SBATCH -p seq
$ * *SBATCH -n 1
$ * *SBATCH -t 00-01:00:00
$ * * POUTRE CONSOLE EN FLEXION SIMPLE
$ * *
$ * * | F
$ * * |
$ * * | |
$ * * |P1 v P2
$ * * |------------------------
$ * * |
$ * * |
$ * *
$ * * Formule analytique de la fl�che en fonction de l'effort :
$ * * u = F*L^3/(3*E*I)
$ * * o� F est la force, L la longueur,
$ * * E le module de Young (210e9 pour l'acier),
$ * * I le moment d'inertie de la section de la poutre (largeur*hauteur^3/12)
$ *
$ * * OPTIONS DU CALCUL ********************************************
$ *
$ * * Dimension 2 et �l�ments finis de type SEG2
$ * OPTI DIME 2 ELEM SEG2;
$ *
$ * * ACQUISITION DES VARIABLES D'ENTREE ***************************
$ *
$ * ** OPTI ACQU 'input.txt';
$ * ** ACQU long*FLOTTANT haut*FLOTTANT larg*FLOTTANT F*FLOTTANT;
$ * long = 0.1;
$ * haut = 0.001;
$ * larg = 0.01;
$ * F = 1.;
$ *
$ * * Section
$ * sect = haut*larg;
$ * * Inertie
$ * inrz = (larg*(haut**3))/12.;
$ *
$ * * MAILLAGE ******************************************************
$ *
$ * * Cr�ation des noeuds
$ * P1 = 0. 0.;
$ * P2 = long 0.;
$ * * Cr�ation de l'�l�ment fini
$ * poutre = DROI 1 P1 P2;
$ *
$ * * MODELE ET MATERIAU ********************************************
$ *
$ * mo_pout = MODE poutre 'MECANIQUE' 'ELASTIQUE' 'ISOTROPE' 'POUT';
$ * ma_pout = MATE mo_pout 'YOUN' 210e9 'NU' 0.3
$ * 'SECT' sect 'INRZ' inrz;
$ *
$ * * CONDITIONS AUX LIMITES ****************************************
$ *
$ * * Encastrement du point P1
$ * enca = BLOQ 'DEPL' 'ROTA' P1;
$ *
$ * * Calcul de la matrice de rigidit�
$ * rigi1 = RIGI mo_pout ma_pout;
$ * rigitot = enca et rigi1;
$ *
$ * * Chargement
$ * char1 = FORC 'FY' (-1.*F) P2;
$ *
$ * * CALCUL ********************************************************
$ *
$ * * R�solution
$ * dep1 = RESO rigitot char1;
Taille de la matrice: 6 Facteur: 1.3867 Performance (Gflop/s): 0.0000
$ *
$ * * Extraction du d�placement au point d'int�r�t
$ * dep_P2 = EXTR dep1 'UY' P2;
$ *
$ * * Export du r�sultat dans un fichier texte
$ * ** OPTI SORT 'output.txt';
$ * ** SORT 'CHAI' dep_P2;
$ * MESS 'dep_P2=' dep_P2;
dep_P2=-1.90476E-03
$ *
$ * * Remarque :
$ * * si dep_P2 �tait une liste (PROG) il faudrait faire
$ * * SORT 'EXCE' dep_P2;
$ *
$ * * FIN DE l'EXECUTION *******************************************
$ *
$ * FIN;

__________________________________________________________________________

0 comments on commit 01441fc

Please sign in to comment.