franta-hg@35: /** franta-hg@35: * Rozšířené atributy – program na správu rozšířených atributů souborů franta-hg@35: * Copyright © 2023 František Kučera (frantovo.cz) franta-hg@35: * franta-hg@35: * This program is free software: you can redistribute it and/or modify franta-hg@35: * it under the terms of the GNU General Public License as published by franta-hg@35: * the Free Software Foundation, either version 3 of the License. franta-hg@35: * franta-hg@35: * This program is distributed in the hope that it will be useful, franta-hg@35: * but WITHOUT ANY WARRANTY; without even the implied warranty of franta-hg@35: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the franta-hg@35: * GNU General Public License for more details. franta-hg@35: * franta-hg@35: * You should have received a copy of the GNU General Public License franta-hg@35: * along with this program. If not, see . franta-hg@35: */ franta-hg@35: package cz.frantovo.rozsireneatributy; franta-hg@35: franta-hg@35: import java.io.IOException; franta-hg@35: import java.io.Writer; franta-hg@35: franta-hg@35: /** franta-hg@35: * Generátor standardních CSV. franta-hg@35: * franta-hg@40: * @author Ing. František Kučera (frantovo.cz) franta-hg@35: */ franta-hg@35: public class CSV { franta-hg@35: franta-hg@35: private final Writer výstup; franta-hg@35: private int sloupec = 0; franta-hg@35: private int početSloupců = -1; franta-hg@35: franta-hg@35: public CSV(Writer výstup) { franta-hg@35: this.výstup = výstup; franta-hg@35: } franta-hg@35: franta-hg@35: public void hodnota(String hodnota) throws IOException { franta-hg@35: if (sloupec > 0) výstup.write(','); franta-hg@35: if (hodnota != null && !hodnota.isEmpty()) { franta-hg@35: výstup.write('"'); franta-hg@35: for (char ch : hodnota.toCharArray()) { franta-hg@35: if (ch == '"') výstup.write('"'); franta-hg@35: výstup.write(ch); franta-hg@35: } franta-hg@35: výstup.write('"'); franta-hg@35: } franta-hg@35: sloupec++; franta-hg@35: výstup.flush(); franta-hg@35: } franta-hg@35: franta-hg@35: public void konecŘádku() throws IOException { franta-hg@35: if (početSloupců < 0) početSloupců = sloupec; franta-hg@35: if (sloupec == početSloupců) { franta-hg@35: výstup.write("\r\n"); franta-hg@35: sloupec = 0; franta-hg@35: } else { franta-hg@35: throw new IOException("Neodpovídá počet sloupců:" franta-hg@35: + " aktuální=" + sloupec franta-hg@35: + " celkový=" + početSloupců franta-hg@35: ); franta-hg@35: } franta-hg@35: výstup.flush(); franta-hg@35: } franta-hg@35: franta-hg@35: }