blob: 04ae99f8a810c0d996f6a6f1aa040f232ce7e564 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.compare.examples.structurecreator;
import java.io.*;
import java.util.*;
import org.eclipse.core.resources.ResourcesPlugin;
public class Util {
private static final String RESOURCE_BUNDLE= "org.eclipse.compare.examples.structurecreator.CompareExampleMessages"; //$NON-NLS-1$
private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
public static String getString(String key) {
try {
return fgResourceBundle.getString(key);
} catch (MissingResourceException e) {
return "!" + key + "!"; //$NON-NLS-2$ //$NON-NLS-1$
}
}
/**
* Reads the contents of the given input stream into a string.
* The function assumes that the input stream uses the platform's default encoding
* (<code>ResourcesPlugin.getEncoding()</code>).
* Returns null if an error occurred.
*/
static String readString(InputStream is) {
if (is == null)
return null;
BufferedReader reader= null;
try {
StringBuffer buffer= new StringBuffer();
char[] part= new char[2048];
int read= 0;
reader= new BufferedReader(new InputStreamReader(is, ResourcesPlugin.getEncoding()));
while ((read= reader.read(part)) != -1)
buffer.append(part, 0, read);
return buffer.toString();
} catch (IOException ex) {
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException ex) {
// we don't log IOException when closing a file
}
}
}
return null;
}
}