This section introduces the file input/output operation system which the Samsung TV application engine supports.
8.1. File API?
Applications can use the file input/output system supported the Samsung TV application engine. Applications can store data they get while they are still working and read them anytime they want to restore the data. All applications perform file input/output operations in a common area. For this reason, a directory where files are created and used should be created. If multiple applications need to share some data, they should do through a file path that they previously promised to use.
File input/output operations are performed by creating a file system object and calling the interface of the object.
8.2. API
The following is a list of interfaces that are provided by the Samsung TV application engine. You can use them in JavaScript.
8.2.1. FileSystem()
FileSystem
Creates a FileSystem object which applications can use. Syntax new FileSystem()
Parameter none
Return Value FileSystem object Remarks none
Example var fileSystemObj = new FileSystem() Enumeration none
Application Development Guide for Internet@TV
8.2.2. openCommonFile()
openCommonFile
Opens a file.Syntax fileSystemObj.openCommonFile(stringFilePath, stringMode)
Parameter
stringFilePath : path containing the name of a file that you want to open stringMode : same as the second parameter of fopen()
r : Open a file for reading. The file must exist.
w : Create an empty file for writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file.
a : Append to a file. Writing operations append data at the end of the file. The file is created if it does not exist.
r+ : Open a file for update both reading and writing. The file must exist.
w+ : Create an empty file for both reading and writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file. a+ : Open a file for reading and appending. All writing operations are performed at
the end of the file, protecting the previous content to be overwritten. You can reposition (fseek, rewind) the internal pointer to anywhere in the file for reading, but writing operations will move it back to the end of file. The file is created if it does not exist.
Return Value file object Remarks none
Example var fileSystemObj = new FileSystem();
var jsFileObj = fileSystemObj.openCommonFile(“testFile.dat”, “r”); Enumeration none
8.2.3. closeCommonFile()
closeCommonFile
Closes a file.Syntax fileSystemObj.closeCommonFile(jsFileObj)
Parameter fileObj: JSFile object that you opened by using openCommonFile() Return Value Boolean
Application Development Guide for Internet@TV
Remarks noneExample
var fileSystemObj = new FileSystem();
var jsFileObj = fileSystemObj.openFile(“testFile.dat”, “r”); var bResult = fileSystemObj.closeCommonFile(jsFileObj); Enumeration none
8.2.4. deleteCommonFile()
deleteCommonFile
Erase a file.Syntax fileSystemObj.deleteCommonFile(stringFilePath) Parameter stringFilePath : path containing the file name Return Value Boolean
Remarks none
Example var fileSystemObj = new FileSystem();
var bResult = fileSystemObj. deleteCommonFile (“testFile.dat”); Enumeration none
8.2.5. createCommonDir()
createCommonDir
Creates a directory.Syntax fileSystemObj.createCommonDir(stringDirectoryPath) Parameter stringDirectoryPath: path containing the directory name Return Value Boolean
Remarks none
Example var fileSystemObj = new FileSystem();
var bResult = fileSystemObj. createCommonDir (“testDirectory”); Enumeration none
Application Development Guide for Internet@TV
8.2.6. deleteCommonDir()
deleteCommonDir
Deletes a directory.Syntax fileSystemObj.deleteCommonDir(stringDirectoryPath) Parameter stringDirectoryPath: name containing the directory name Return Value Boolean
Remarks none
Example var fileSystemObj = new FileSystem();
var bResult = fileSystemObj. deleteCommonDir (“testDirectory”); Enumeration none
8.2.7. isValidCommonPath()
isValidCommonPath
Verifies if the path already exists.Syntax fileSystemObj.isValidCommonPath(stringPath) Parameter stringPath: path
Return Value int 0 : JS function failure 1 : valid 2 : invalid Remarks none
Example var fileSystemObj = new FileSystem();
var bResult = fileSystemObj. isValidCommonPath (“testDirectory”); Enumeration none
8.2.8. readLine()
readLine
Reads a line from an open file.
Application Development Guide for Internet@TV
Parameter noneReturn Value string Remarks None
Example var jsFileObj = fileSystemObj.openFile(“testFile.dat”, “r”); var stringResult = jsFileObj. readLine();
Enumeration none
8.2.9. writeLine()
writeLine
Writes a line in an open file.
Syntax jsFileObj.writeLine(string)
Parameter string: string that you will write in the file. Return Value boolean
Remarks none
Example var jsFileObj = fileSystemObj.openFile(“testFile.dat”, “w”); var bResult = jsFileObj. writeLine(“testString”);
Enumeration none
8.2.10.
readAll()
readAll
Reads more than one line from an open file. Syntax jsFileObj.readAll() Parameter none
Return Value string Remarks none
Example var jsFileObj = fileSystemObj.openFile(“testFile.dat”, “r”); var stringResult = jsFileObj. readAll();
Application Development Guide for Internet@TV
8.2.11.
writeAll()
writeAll
Writes more than one line in an open file. Syntax jsFileObj.writeAll() Parameter none
Return Value boolean Remarks none
Example var jsFileObj = fileSystemObj.openFile(“testFile.dat”, “r”); var bResult = jsFileObj. writeAll(varLongString);
Application Development Guide for Internet@TV
9. Appendix
9.1. Country Code
You can get this code from Application Manager. Refer ch. 6.7, for more details.
Nations
Code
Nations
Code
ALBANIA AL PORTUGAL PT ANDORRA AD ROMANIA RO AUSTRIA AT SERBIA RS BELGIUM BE SLOVAKIA SK BOSNIA BA SLOVENIA SI BULGARIA BG SPAIN ES CIS RU SWEDEN SE CROATIA HR SWITZERLAND CH CYPRUS CY UK GB CZECH CZ AMERICA US DENMARK DK CANADA CA FINLAND FI MEXICO MX FRANCE FR ARGENTINA AR GERMANY DE CHILE CL GREECE GR PERU PE HUNGRARY HU THAILAND TH ICELAND IS VIETNAM VN IRELAND IE MALAYSIA MY ITALY IT INDONESIA ID LUXEMBOURG LU PHILIPPINES PH MACEDONIA MK BRAZIL BR MONTENEGRO ME ALGERIA DZ NETHERLAND NL MOROCCO MA NORWAY NO TUNISIA TN POLAND PL
Application Development Guide for Internet@TV
9.2. Language Code
You can get this code from Application Manager. Refer ch. 6.7, for more details.
Language
Code
Language
Code
Korean 0 Spanish 24 English 1 Swedish 25 Spanish(America) 2 Turkish 26 French(America) 3 Chinese 27 Portuguese(America) 4 Hongkong 28 Bulgarian 5 Taiwan 29 Croatian 6 Japanese 30 Czech 7 Maori 31 Danish 8 CMN 32 Dutch 9 YUE 33 Finnish 10 Hindi 34 French 11 Estonian 35 German 12 Latvian 36
Modern Greek 13 Lithuanian 37
Hungarian 14 Arabic 38 Italian 15 Persian 39 Norwegian 16 QAA 40 English(GB) 17 AD 41 Polish 18 Catalan 42 Portuguese 19 VAL 43 Romany 20 Hebrew 44 Russian 21 OTHER 45 Serbian 22 Thai 46 Slovak 23
Application Development Guide for Internet@TV
9.3. Region Code
You can get this code from Application Manager. Refer ch. 6.7, for more details.
Code
Region
KOR Korea
USA USA/Canada/Mexico
BRA Brazil, Paraguay, Uruguay, Argentine PANEURO Europe
CHI China
HKG Hong Kong
ARB Arab
PANNORDIG Nordic
SOUTHEASTASIA South-East Asia (Vietnam, Thailand, India, China, Iran, Israel, Central Asia, East Asia, Africa)
ASIA_ATV South-East Asia (Vietnam, Thailand, India, China, Iran, Israel, Central Asia, East Asia, Africa)
ASIA_DTV Australia , New Zealand, Singapore TW Taiwan, Columbia
NORTHAFRICA TURKEY, MOROCCO, TUNISIA
EA_DTV Indonesia, Malaysia, Republic of South Africa, Vietnam
CIS CIS
PHI Philippine S_AFR_DTV South Africa DTV