1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
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
17package com.android.email.mail.store.imap;
18
19import com.android.emailcommon.utility.Utility;
20
21import java.io.ByteArrayInputStream;
22import java.io.InputStream;
23
24/**
25 * Subclass of {@link ImapString} used for non literals.
26 */
27public class ImapSimpleString extends ImapString {
28    private String mString;
29
30    /* package */  ImapSimpleString(String string) {
31        mString = (string != null) ? string : "";
32    }
33
34    @Override
35    public void destroy() {
36        mString = null;
37        super.destroy();
38    }
39
40    @Override
41    public String getString() {
42        return mString;
43    }
44
45    @Override
46    public InputStream getAsStream() {
47        return new ByteArrayInputStream(Utility.toAscii(mString));
48    }
49
50    @Override
51    public String toString() {
52        // Purposefully not return just mString, in order to prevent using it instead of getString.
53        return "\"" + mString + "\"";
54    }
55}
56