Home | History | Annotate | Download | only in imap
      1 /*
      2  * Copyright (C) 2015 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 
     17 package com.android.voicemail.impl.mail.store.imap;
     18 
     19 import com.android.voicemail.impl.VvmLog;
     20 import java.io.ByteArrayInputStream;
     21 import java.io.InputStream;
     22 import java.io.UnsupportedEncodingException;
     23 
     24 /** Subclass of {@link ImapString} used for non literals. */
     25 public class ImapSimpleString extends ImapString {
     26   private final String TAG = "ImapSimpleString";
     27   private String string;
     28 
     29   /* package */ ImapSimpleString(String string) {
     30     this.string = (string != null) ? string : "";
     31   }
     32 
     33   @Override
     34   public void destroy() {
     35     string = null;
     36     super.destroy();
     37   }
     38 
     39   @Override
     40   public String getString() {
     41     return string;
     42   }
     43 
     44   @Override
     45   public InputStream getAsStream() {
     46     try {
     47       return new ByteArrayInputStream(string.getBytes("US-ASCII"));
     48     } catch (UnsupportedEncodingException e) {
     49       VvmLog.e(TAG, "Unsupported encoding: ", e);
     50     }
     51     return null;
     52   }
     53 
     54   @Override
     55   public String toString() {
     56     // Purposefully not return just mString, in order to prevent using it instead of getString.
     57     return "\"" + string + "\"";
     58   }
     59 }
     60