strings.java

来自「Sony Ericsson手机上的Facebook客户端全套代码」· Java 代码 · 共 108 行

JAVA
108
字号
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   Strings.java

package com.sonyericsson.fb.strings;

import com.sonyericsson.fb.utils.Logger;
import java.io.IOException;
import java.io.InputStream;

public class Strings
{

    public static Strings getInstance()
    {
        return instance;
    }

    private Strings()
    {
        String language = System.getProperty("microedition.locale");
        if(language != null)
            language = language.substring(0, 2);
        if(language == null)
            language = "en";
        strings = readLines(getStream("/" + language + "/strings.txt"));
        if(strings.length == 0)
        {
            language = "en";
            strings = readLines(getStream("/" + language + "/strings.txt"));
        }
    }

    public static String get(int key)
    {
        if(instance.strings != null && key >= 0 && key < instance.strings.length)
            return instance.strings[key];
        else
            return "?" + key + "?";
    }

    private InputStream getStream(String filename)
    {
        InputStream stream = null;
        try
        {
            stream = getClass().getResourceAsStream('/' + filename);
            if(stream == null)
                throw new IOException("File not found: " + filename);
        }
        catch(Throwable t)
        {
            Logger.printErrorln("Could not load language file '" + filename + "': " + t.getMessage());
            return null;
        }
        return stream;
    }

    private String[] readLines(InputStream is)
    {
        String strings[] = null;
        if(is != null)
        {
            int EOF = -1;
            int stringIndex = 0;
            try
            {
                StringBuffer buffer = new StringBuffer();
                do
                {
                    int c;
                    if((c = is.read()) == -1)
                        break;
                    if(c != 13)
                        if(c == 10)
                        {
                            String str = buffer.toString();
                            buffer.setLength(0);
                            if(strings == null)
                            {
                                int nrStrings = Integer.parseInt(str);
                                strings = new String[nrStrings];
                            } else
                            {
                                strings[stringIndex++] = str;
                            }
                        } else
                        {
                            buffer.append((char)c);
                        }
                } while(true);
                is.close();
            }
            catch(Throwable t)
            {
                Logger.printErrorln("Error when loading strings: " + t.getMessage());
            }
        }
        return strings;
    }

    private static final String defaultLanguage = "en";
    private static final Strings instance = new Strings();
    public String strings[];

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?