/**
 * Copyright (C) 2009 eXo Platform SAS.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

package org.exoplatform.services.chars.chardet;


public class Detector extends PSMDetector implements ICharsetDetector
{

   ICharsetDetectionObserver mObserver = null;

   public Detector()
   {
      super();
   }

   public Detector(int langFlag)
   {
      super(langFlag);
   }

   public void init(ICharsetDetectionObserver aObserver)
   {
      mObserver = aObserver;
   }

   public boolean doIt(byte[] aBuf, int aLen, boolean oDontFeedMe)
   {
      if (aBuf == null || oDontFeedMe)
         return false;

      this.handleData(aBuf, aLen);
      return mDone;
   }


   public void done()
   {
      this.dataEnd();
   }

   public void report(String charset)
   {
      if (mObserver != null)
         mObserver.notify(charset);
   }

   public boolean isAscii(byte[] aBuf, int aLen)
   {
      for (int i = 0; i < aLen; i++)
      {
         if ((0x0080 & aBuf[i]) != 0)
         {
            return false;
         }
      }
      return true;
   }
}

