Example usage for java.util SortedMap getClass

List of usage examples for java.util SortedMap getClass

Introduction

In this page you can find the example usage for java.util SortedMap getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:uk.org.sappho.applications.transcript.service.registry.WorkingCopy.java

private SortedMap<String, Object> getJsonProperties(String environment, String application)
        throws TranscriptException {

    SortedMap<String, Object> properties = new TreeMap<String, Object>();
    synchronized (getLock()) {
        try {//w ww  .  jav a  2 s.  co  m
            File jsonFile = getUpToDatePath(getJsonFilename(environment, application));
            if (jsonFile.exists()) {
                FileReader fileReader = new FileReader(jsonFile);
                try {
                    properties = new Gson().fromJson(fileReader, properties.getClass());
                } finally {
                    try {
                        fileReader.close();
                    } catch (Throwable throwable) {
                    }
                }
            }
        } catch (Throwable throwable) {
            throw new TranscriptException("Unable to read " + getJsonFilename(environment, application),
                    throwable);
        }
    }
    return properties;
}

From source file:uk.org.sappho.applications.transcript.service.registry.WorkingCopy.java

private void putProperties(String environment, String application, SortedMap<String, Object> properties)
        throws TranscriptException {

    synchronized (getLock()) {
        checkWritable();//from  w w  w. j ava2s. com
        File jsonFile = getUpToDatePath(getJsonFilename(environment, application));
        File directory = new File(
                new File(transcriptParameters.getWorkingCopyPath(), transcriptParameters.getWorkingCopyId()),
                environment);
        boolean isNewDirectory = !directory.exists();
        boolean isNewFile = !jsonFile.exists();
        try {
            if (isNewDirectory) {
                if (!directory.mkdir()) {
                    unableToCreateNewEnvironment(environment);
                }
            } else {
                if (!directory.isDirectory()) {
                    unableToCreateNewEnvironment(environment);
                }
            }
            JsonWriter jsonWriter = new JsonWriter(new FileWriter(jsonFile));
            try {
                jsonWriter.setIndent("    ");
                jsonWriter.setHtmlSafe(true);
                new Gson().toJson(properties, properties.getClass(), jsonWriter);
                jsonWriter.close();
            } finally {
                try {
                    jsonWriter.close();
                } catch (Throwable closeException) {
                }
            }
            if (isNewDirectory) {
                versionControlSystem.commit(environment, true);
            } else {
                versionControlSystem.commit(getJsonFilename(environment, application), isNewFile);
            }
        } catch (Throwable throwable) {
            if (isNewFile) {
                try {
                    FileUtils.forceDelete(isNewDirectory ? directory : jsonFile);
                } catch (Throwable deleteException) {
                }
            }
            throw new TranscriptException("Unable to write " + getJsonFilename(environment, application),
                    throwable);
        }
    }
}