1 /* 2 * Copyright (C) 2011 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 18 package android.filterpacks.text; 19 20 import android.filterfw.core.Filter; 21 import android.filterfw.core.FilterContext; 22 import android.filterfw.core.Frame; 23 import android.filterfw.core.FrameFormat; 24 import android.filterfw.core.GenerateFieldPort; 25 import android.filterfw.format.ObjectFormat; 26 27 /** 28 * @hide 29 */ 30 public class StringSource extends Filter { 31 32 @GenerateFieldPort(name = "stringValue") 33 private String mString; 34 35 private FrameFormat mOutputFormat; 36 37 public StringSource(String name) { 38 super(name); 39 } 40 41 @Override 42 public void setupPorts() { 43 mOutputFormat = ObjectFormat.fromClass(String.class, FrameFormat.TARGET_SIMPLE); 44 addOutputPort("string", mOutputFormat); 45 } 46 47 @Override 48 public void process(FilterContext env) { 49 Frame output = env.getFrameManager().newFrame(mOutputFormat); 50 output.setObjectValue(mString); 51 output.setTimestamp(Frame.TIMESTAMP_UNKNOWN); 52 pushOutput("string", output); 53 closeOutputPort("string"); 54 } 55 56 57 } 58