1 package org.sapia.ubik.net.mplex; 2 3 import java.io.UnsupportedEncodingException ; 4 5 6 25 public class SimpleStreamSelector implements StreamSelector { 26 public static final byte TYPE_STARTS_WITH = 1; 27 public static final byte TYPE_CONTAINS = 2; 28 private String _theValue; 29 private int _theType; 30 31 34 public SimpleStreamSelector(String aValue, int aType) { 35 _theValue = aValue; 36 _theType = aType; 37 } 38 39 45 public boolean selectStream(byte[] header) { 46 try { 47 String aStringValue = new String (header, 0, header.length, "UTF-8"); 48 49 if (_theType == TYPE_CONTAINS) { 50 return aStringValue.indexOf(_theValue) >= 0; 51 } else if (_theType == TYPE_STARTS_WITH) { 52 return aStringValue.startsWith(_theValue); 53 } else { 54 return false; 55 } 56 } catch (UnsupportedEncodingException e) { 57 e.printStackTrace(); 58 59 return false; 60 } 61 } 62 } 63 | Popular Tags |