1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
private Bilan unBilan;
private static final String SECTION1 = "============================== SECTION 1 ==============================";
private static final String SECTION2 = "============================== SECTION 2 ==============================";
private static final String SECTION3 = "============================== SECTION 3 ==============================";
private static final String NOM_BATCH = "Nom du BATCH: ";
private static final String VERSION_ARCHITECTURE = "Version Architecture BATCH: ";
private static final String VERSION_APPLI = "Version: ";
private static final String DEBUT = "Début du Batch : ";
private static final String FIN = "Fin du Batch : ";
private static final String DUREE = "Duree du Batch: ";
private static final Properties PROPS = System.getProperties();
private String formatMimeMessageToString(File file) throws FileNotFoundException, MessagingException
{
// utilisation de l'API MimeMessage pour ouvrir les fichiers .eml
PROPS.put("mail.host", "smtp.dummydomain.com");
PROPS.put("mail.transport.protocol", "smtp");
Session mailSession = Session.getDefaultInstance(PROPS, null);
InputStream source = new FileInputStream(file);
MimeMessage message = new MimeMessage(mailSession, source);
// utilisation de l'API Email pour la lecture du corps des messgages.
Email email = EmailConverter.mimeMessageToEmail(message);
return email.getText();
}
public void lireTout() throws IOException
{
ArrayList<String> allFiles = new ArrayList<String>();
listeRepertoire(new File("C:\\Users\\moi\\Desktop\\bilans batch satelit 2016\\dossiers extraites"), allFiles);
try
{
File f;
String nomBatch = "";
String versionArchitecture = "";
String versionAppli = "";
String heureDebut = "";
String bilan = "";
String heureFin = "";
String duree = "";
for (String file : allFiles)
{
f = new File(file);
System.out.println(f.getAbsolutePath());
String body = null;
if (!f.getName().endsWith(".html"))
{
// corps du message
body = formatMimeMessageToString(f);
boolean tokenFound = false;
try (BufferedReader reader = new BufferedReader(new StringReader(body)))
{
String line = null;
while ((line = reader.readLine()) != null)
{
/*============================== SECTION 1 ==============================*/
if (line.contains(NOM_BATCH))
{
nomBatch = decouper(line, ":");
if (nomBatch != null)
{
unBilan = new Bilan(nomBatch);
unBilan.setIdBatch(f.getAbsolutePath());
}
}
if (line.contains(VERSION_ARCHITECTURE))
{
versionArchitecture = decouper(line, ":");
if (versionArchitecture != null)
{
unBilan.setVersionArchitecture(versionArchitecture);
}
}
if (line.contains(VERSION_APPLI))
{
versionAppli = decouper(line, ":");
if (versionAppli != null)
{
unBilan.setVersionAppli(versionAppli);
}
}
if (line.contains(DEBUT))
{
heureDebut = decouper(line, ":");
if (heureDebut != null)
{
unBilan.setHeureDebut(heureDebut);
}
}
/*============================== SECTION 2 ==============================*/
if (line.equals(SECTION2))
{
tokenFound = true;
}
else if (line.equals(SECTION3))
{
tokenFound = false;
bilan = "";
}
if (tokenFound)
{
if (!line.contains(SECTION2))
{
bilan += line + "\n";
if (bilan != null)
{
unBilan.setBilanBatch(bilan.trim());
}
}
}
/*============================== SECTION 3 ==============================*/
if (line.contains(FIN))
{
heureFin = decouper(line, ":");
if (heureFin != null)
{
unBilan.setHeureFin(heureFin);
}
}
if (line.contains(DUREE))
{
duree = decouper(line, ":");
if (duree != null)
{
unBilan.setDuree(duree);
}
}
if (unBilan != null)
{
lesBilans.add(unBilan);
}
}
}
}
}
}
catch (IOException | MessagingException exception)
{
exception.printStackTrace();
}
} |
Partager