Java tutorial
/* * This file is part of MystudiesMyteaching application. * * MystudiesMyteaching application is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * MystudiesMyteaching application is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with MystudiesMyteaching application. If not, see <http://www.gnu.org/licenses/>. */ package fi.helsinki.opintoni.sampledata; import com.google.common.io.Files; import java.io.File; import java.io.IOException; import java.nio.charset.Charset; import java.util.Base64; public class SampleDataFiles { private static final String PREFIX = "src/test/resources/sampledata/"; public static String toText(String path) { try { return Files.toString(new File(PREFIX + path), Charset.forName("UTF-8")); } catch (IOException e) { throw new RuntimeException(e); } } public static String imageToBase64(String path) { try { return Base64.getEncoder().encodeToString(Files.toByteArray(new File(PREFIX + path))); } catch (IOException e) { throw new RuntimeException(e); } } }