PageRenderTime 19ms CodeModel.GetById 9ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/plugin-module-codegen-api/src/main/java/com/atlassian/plugins/codegen/ResourceFile.java

https://bitbucket.org/mmeinhold/amps
Java | 58 lines | 44 code | 11 blank | 3 comment | 0 complexity | 33cc793eb84f0ecff855b5cf5c3fe40b MD5 | raw file
 1package com.atlassian.plugins.codegen;
 2
 3import java.nio.charset.Charset;
 4
 5import static com.google.common.base.Preconditions.checkNotNull;
 6
 7/**
 8 * Describes a resource file that should be added to the project.
 9 */
10public class ResourceFile implements PluginProjectChange
11{
12    private final String relativePath;
13    private final String name;
14    private final byte[] content;
15
16    public static ResourceFile resourceFile(String relativePath, String name, String content)
17    {
18        return new ResourceFile(relativePath, name, content.getBytes(Charset.forName("UTF-8")));
19    }
20
21    public static ResourceFile resourceFile(String relativePath, String name, byte[] content)
22    {
23        return new ResourceFile(relativePath, name, content);
24    }
25    
26    private ResourceFile(String relativePath, String name, byte[] content)
27    {
28        this.relativePath = normalizePath(checkNotNull(relativePath, "relativePath"));
29        this.name = checkNotNull(name, "name");
30        this.content = checkNotNull(content, "content");
31    }
32
33    public String getRelativePath()
34    {
35        return relativePath;
36    }
37
38    public String getName()
39    {
40        return name;
41    }
42    
43    public byte[] getContent()
44    {
45        return content;
46    }
47    
48    private String normalizePath(String path)
49    {
50        return (path.endsWith("/")) ? path.substring(0, path.length() - 1) : path;
51    }
52        
53    @Override
54    public String toString()
55    {
56        return "[resource: " + name + "]";
57    }
58}