Search in sources :

Example 1 with LocalFileCodec

use of com.continuuity.weave.internal.json.LocalFileCodec in project weave by continuuity.

the class YarnWeavePreparer method saveLocalFiles.

/**
   * Serializes the list of files that needs to localize from AM to Container.
   */
private void saveLocalFiles(Map<String, LocalFile> localFiles, Set<String> includes) throws IOException {
    Map<String, LocalFile> localize = ImmutableMap.copyOf(Maps.filterKeys(localFiles, Predicates.in(includes)));
    LOG.debug("Create and copy {}", Constants.Files.LOCALIZE_FILES);
    Location location = createTempLocation(Constants.Files.LOCALIZE_FILES);
    Writer writer = new OutputStreamWriter(location.getOutputStream(), Charsets.UTF_8);
    try {
        new GsonBuilder().registerTypeAdapter(LocalFile.class, new LocalFileCodec()).create().toJson(localize.values(), new TypeToken<List<LocalFile>>() {
        }.getType(), writer);
    } finally {
        writer.close();
    }
    LOG.debug("Done {}", Constants.Files.LOCALIZE_FILES);
    localFiles.put(Constants.Files.LOCALIZE_FILES, createLocalFile(Constants.Files.LOCALIZE_FILES, location));
}
Also used : LocalFileCodec(com.continuuity.weave.internal.json.LocalFileCodec) LocalFile(com.continuuity.weave.api.LocalFile) DefaultLocalFile(com.continuuity.weave.internal.DefaultLocalFile) GsonBuilder(com.google.gson.GsonBuilder) TypeToken(com.google.common.reflect.TypeToken) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) Location(com.continuuity.weave.filesystem.Location)

Aggregations

LocalFile (com.continuuity.weave.api.LocalFile)1 Location (com.continuuity.weave.filesystem.Location)1 DefaultLocalFile (com.continuuity.weave.internal.DefaultLocalFile)1 LocalFileCodec (com.continuuity.weave.internal.json.LocalFileCodec)1 TypeToken (com.google.common.reflect.TypeToken)1 GsonBuilder (com.google.gson.GsonBuilder)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1