Skip to content
This repository has been archived by the owner on Dec 28, 2019. It is now read-only.

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
shalupov committed Jul 6, 2015
1 parent ff4aa51 commit 98f9a0d
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@

public class CloudFormationFileType extends LanguageFileType implements FileTypeIdentifiableByVirtualFile {
public static final CloudFormationFileType INSTANCE = new CloudFormationFileType();
public static final String DEFAULT_EXTENSION = "template";

private static final String EXTENSION = "template";
private static final byte[] BYTES_TO_DETECT_CFN_FILE = CloudFormationSections.FormatVersion.getBytes(Charsets.US_ASCII);

public CloudFormationFileType() {
super(JsonLanguage.INSTANCE);
Expand Down Expand Up @@ -54,8 +56,7 @@ public Icon getIcon() {

@Override
public boolean isMyFileType(@NotNull VirtualFile file) {
return CloudFormationFileType.DEFAULT_EXTENSION.equalsIgnoreCase(file.getExtension()) &&
detectFromContent(file);
return CloudFormationFileType.EXTENSION.equalsIgnoreCase(file.getExtension()) && detectFromContent(file);
}

private boolean detectFromContent(@NotNull VirtualFile file) {
Expand All @@ -65,7 +66,7 @@ private boolean detectFromContent(@NotNull VirtualFile file) {
return FileUtil.processFirstBytes(inputStream, 1024, new Processor<ByteSequence>() {
@Override
public boolean process(ByteSequence byteSequence) {
return findArray(byteSequence.getBytes(), CloudFormationSections.FormatVersion.getBytes(Charsets.US_ASCII)) >= 0;
return findArray(byteSequence.getBytes(), BYTES_TO_DETECT_CFN_FILE) >= 0;
}
});
} finally {
Expand Down

0 comments on commit 98f9a0d

Please sign in to comment.