blob: 343577b45d2a31a73f0f2d83f4e6a03c71b900bb [file] [log] [blame]
/*****************************************************************************
* Copyright (c) 2019 CEA LIST.
*
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Xavier Le Pallec (for CEA LIST) xlepallec@lilo.org - Bug 558456
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.clazz.lf.classtextualedition.webpages;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.eclipse.papyrus.uml.diagram.clazz.lf.classtextualedition.Activator;
/**
* This class is just used to load files in the plug-in jar file. See the getContentOfFileLocatedInTheJar method.
*
*/
public class ResourceAccessUtils {
private static final Activator LOGGER = Activator.getDefault();
private static ResourceAccessUtils instance;
private ResourceAccessUtils() {
// to prevent instatiation
}
public static ResourceAccessUtils getInstance() {
if (instance == null) {
instance = new ResourceAccessUtils();
}
return instance;
}
/**
* This methods loads a file in a the plug-in jar file.
*
* @param nameFile
* the full name of the file.
* @return the content of the file.
*/
public String getContentOfFileLocatedInTheJar(String nameFile) {
InputStream in = ResourceAccessUtils.class.getResourceAsStream(nameFile);
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder fileContent = new StringBuilder(""); //$NON-NLS-1$
try {
String currentLine = reader.readLine();
while (currentLine != null) {
fileContent.append(currentLine + "\n"); //$NON-NLS-1$
currentLine = reader.readLine();
}
reader.close();
in.close();
} catch (IOException exception) {
LOGGER.logError(exception.toString(), exception);
}
return fileContent.toString();
}
}