1 /* 2 * Copyright the original author or authors. 3 * 4 * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.mozilla.org/MPL/MPL-1.1.html 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 import org.as2lib.core.BasicClass; 18 import org.as2lib.io.file.TextFile; 19 import org.as2lib.data.type.Byte; 20 import org.as2lib.env.reflect.ReflectUtil; 21 22 /** 23 * {@code SimpleTextFile} represents the simplest way for accessing the file informations. 24 * 25 * <p>Supports all necessary features for {@code TextFile} without any other advantages. 26 * 27 * @author Martin Heidegger 28 * @version 2.0 29 */ 30 class org.as2lib.io.file.SimpleTextFile extends BasicClass implements TextFile { 31 32 /** Content of the file. */ 33 private var source:String; 34 35 /** Location of the file. */ 36 private var uri:String; 37 38 /** Size of the file in bytes. */ 39 private var size:Byte; 40 41 /** 42 * Constructs a new {@code SimpleTextFile}. 43 * 44 * @param source content of the {@code TextFile} to create 45 * @param size size in {@link Byte} of the loaded resource 46 * @param uri location of the loaded resource 47 */ 48 public function SimpleTextFile(source:String, size:Byte, uri:String) { 49 this.source = source; 50 this.uri = uri; 51 this.size = size; 52 } 53 54 /** 55 * Returns the location of the resource corresponding to the content. 56 * 57 * <p>Note: Might be the URI of the resource or null if its not requestable 58 * or the internal location corresponding to the instance path (if its without 59 * any connection to a real file). 60 * 61 * @return location of the resource related to the content 62 */ 63 public function getLocation(Void):String { 64 return uri; 65 } 66 67 /** 68 * Returns the content of the file 69 * 70 * @return content of the file 71 * @see TextFile#getContent 72 */ 73 public function getContent(Void):String { 74 return source; 75 } 76 77 /** 78 * Returns the size of the file in bytes. 79 * 80 * @return size of the file in bytes 81 */ 82 public function getSize(Void):Byte { 83 return size; 84 } 85 86 /** 87 * Extended Stringifier 88 * 89 * Example: 90 * {@code [type org.as2lib.io.file.SimpleTextFile | Location: MyTextFile.txt; Size: 12KB; ]} 91 * 92 * @return the {@code TextFile} as string 93 */ 94 public function toString():String { 95 var result:String; 96 result = "[type " + ReflectUtil.getTypeNameForInstance(this) 97 + " | Location: " + getLocation() 98 + "; Size: " + getSize().toString(false, 2) 99 + "; ]"; 100 return result; 101 } 102 }