com.storezhang.android.flavor.FlavorUtils.java Source code

Java tutorial

Introduction

Here is the source code for com.storezhang.android.flavor.FlavorUtils.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.storezhang.android.flavor;

import com.google.common.io.Files;
import com.google.common.io.LineProcessor;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Android???
 *
 * @author storezhang
 */
public class FlavorUtils {

    public static String build() throws IOException {
        final List<Map<String, String>> flavors = new ArrayList<Map<String, String>>();

        File flavorsFile = new File("flavors.txt");
        Files.readLines(flavorsFile, Charset.forName("UTF-8"), new LineProcessor<Void>() {

            @Override
            public boolean processLine(String line) throws IOException {
                String[] flavorString = line.split("\t");
                Map<String, String> flavor = new HashMap<String, String>();
                flavor.put("name", "_" + (flavorString[0].substring(0, 1).toUpperCase()
                        + flavorString[0].substring(1).replaceFirst("\\w", "").replaceAll("/", "")).trim());
                flavor.put("umeng", flavorString[1].trim());
                flavor.put("youmi", flavorString[2].trim());
                flavors.add(flavor);

                return true;
            }

            @Override
            public Void getResult() {
                return null;
            }
        });

        Map<String, Object> model = new HashMap<String, Object>();
        model.put("flavors", flavors);
        String flavorString = HttlUtils.render("flavor.httl", model);

        return flavorString;
    }

    public static void main(String[] args) throws IOException {
        System.err.println("---->" + build());
    }
}