X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.compressions%2Fsrc%2Forg%2Fsimantics%2Fcompressions%2FCompressions.java;h=66a29e7cb473c2ae15e8eb65ed359a7ace28022b;hp=c13291d995cd9497329d97053e79b9fff49d5089;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.compressions/src/org/simantics/compressions/Compressions.java b/bundles/org.simantics.compressions/src/org/simantics/compressions/Compressions.java index c13291d99..66a29e7cb 100644 --- a/bundles/org.simantics.compressions/src/org/simantics/compressions/Compressions.java +++ b/bundles/org.simantics.compressions/src/org/simantics/compressions/Compressions.java @@ -1,92 +1,92 @@ -/******************************************************************************* - * Copyright (c) 2007, 2012 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.compressions; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceReference; - -/** - * A facade for accessing {@link CompressionCodec} implementations. - * - * @author Tuukka Lehtonen - */ -public final class Compressions { - - private static final Map CODECS = new HashMap<>(); - private static boolean initialized = false; - - public static final String LZ4 = "LZ4"; - public static final String FASTLZ = "FASTLZ"; - - private static void collectCodecs() { - try { - Collection> serv = Activator.getContext().getServiceReferences(CompressionCodec.class, null); - for (ServiceReference service : serv) { - CompressionCodec codec = Activator.getContext().getService(service); - CODECS.put(codec.getId(), codec); - } - initialized = true; - } catch (InvalidSyntaxException e) { - e.printStackTrace(); - } - } - - - /** - * Get a {@link CompressionCodec} matching the requested name. - * @param - * - * @param codec codec name - * @return - * @return matching codec - * @see #FASTLZ - * @see #LZ4 - */ - public static CompressionCodec get(String codecId) { - if (!initialized) { - collectCodecs(); - } - CompressionCodec codec = CODECS.get(codecId); - if (codec == null) { - throw new IllegalArgumentException("No codec with id " + codecId + " installed"); - } - return codec; - } - - /** - * @param codecId - * @param file - * @return - * @throws FileNotFoundException - */ - public static OutputStream write(String codecId, File file) throws FileNotFoundException { - return get(codecId).write(file); - } - - /** - * @param codecId - * @param file - * @return - * @throws FileNotFoundException - */ - public static InputStream read(String codecId, File file) throws FileNotFoundException { - return get(codecId).read(file); - } +/******************************************************************************* + * Copyright (c) 2007, 2012 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.compressions; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.osgi.framework.InvalidSyntaxException; +import org.osgi.framework.ServiceReference; + +/** + * A facade for accessing {@link CompressionCodec} implementations. + * + * @author Tuukka Lehtonen + */ +public final class Compressions { + + private static final Map CODECS = new HashMap<>(); + private static boolean initialized = false; + + public static final String LZ4 = "LZ4"; + public static final String FASTLZ = "FASTLZ"; + + private static void collectCodecs() { + try { + Collection> serv = Activator.getContext().getServiceReferences(CompressionCodec.class, null); + for (ServiceReference service : serv) { + CompressionCodec codec = Activator.getContext().getService(service); + CODECS.put(codec.getId(), codec); + } + initialized = true; + } catch (InvalidSyntaxException e) { + e.printStackTrace(); + } + } + + + /** + * Get a {@link CompressionCodec} matching the requested name. + * @param + * + * @param codec codec name + * @return + * @return matching codec + * @see #FASTLZ + * @see #LZ4 + */ + public static CompressionCodec get(String codecId) { + if (!initialized) { + collectCodecs(); + } + CompressionCodec codec = CODECS.get(codecId); + if (codec == null) { + throw new IllegalArgumentException("No codec with id " + codecId + " installed"); + } + return codec; + } + + /** + * @param codecId + * @param file + * @return + * @throws FileNotFoundException + */ + public static OutputStream write(String codecId, File file) throws FileNotFoundException { + return get(codecId).write(file); + } + + /** + * @param codecId + * @param file + * @return + * @throws FileNotFoundException + */ + public static InputStream read(String codecId, File file) throws FileNotFoundException { + return get(codecId).read(file); + } } \ No newline at end of file