PR2-Gruppenprojekt/PR2Projekt/site/jacoco/de.hs_mannheim.informatik.mvn/LogTest.java.html

40 lines
3.6 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>LogTest.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">MvnDemo</a> &gt; <a href="index.source.html" class="el_package">de.hs_mannheim.informatik.mvn</a> &gt; <span class="el_source">LogTest.java</span></div><h1>LogTest.java</h1><pre class="source lang-java linenums">package de.hs_mannheim.informatik.mvn;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
<span class="nc" id="L10">public class LogTest {</span>
<span class="nc" id="L11"> private static final Logger logger = LogManager.getLogger(LogTest.class);</span>
public static void newRecord(String path, String username, String time) throws FileNotFoundException {
<span class="nc" id="L14"> String timePart = time.substring(&quot;Zeit: &quot;.length()).trim();</span>
<span class="nc" id="L15"> String[] parts = path.split(&quot;/&quot;);</span>
<span class="nc" id="L16"> String filename = parts[parts.length - 1];</span>
<span class="nc" id="L17"> int dotIndex = filename.lastIndexOf(&quot;.&quot;);</span>
<span class="nc" id="L18"> String result = filename.substring(0, dotIndex);</span>
<span class="nc" id="L19"> String ordner = &quot;C:/Users/Berat/Desktop/hitoriNew/src/main/java/de/hs_mannheim/informatik/mvn/Hitori_Highscores/&quot;;</span>
<span class="nc" id="L20"> String filetype = &quot;.txt&quot;;</span>
<span class="nc" id="L21"> String filepath = ordner + result + filetype;</span>
<span class="nc" id="L22"> System.out.println(&quot;A: &quot; + filepath);</span>
<span class="nc" id="L23"> Scanner sc = new Scanner(filepath);</span>
<span class="nc bnc" id="L24" title="All 2 branches missed."> while (sc.hasNextLine()) {</span>
<span class="nc" id="L25"> sc.nextLine();</span>
}
<span class="nc" id="L27"> sc.close();</span>
<span class="nc" id="L29"> try (BufferedWriter writer = new BufferedWriter(new FileWriter(filepath, true))) {</span>
<span class="nc" id="L30"> String eintrag = timePart + &quot; &quot; + username;</span>
<span class="nc" id="L31"> logger.info(&quot;Neuer Eintrag: {}&quot;, eintrag);</span>
<span class="nc" id="L33"> writer.write(eintrag);</span>
<span class="nc" id="L34"> writer.newLine();</span>
<span class="nc" id="L35"> } catch (IOException e) {</span>
<span class="nc" id="L36"> logger.error(&quot;Fehler beim Schreiben in die Datei: &quot; + filepath, e);</span>
<span class="nc" id="L37"> }</span>
<span class="nc" id="L38"> }</span>
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.12.202403310830</span></div></body></html>