Android Open Source - EBrowser Hex Encoder






From Project

Back to project page EBrowser.

License

The source code is released under:

GNU General Public License

If you think the Android project EBrowser listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.emergent.android.weave.client;
//from w  w w .  j a v  a  2  s.c  o  m
import java.io.IOException;
import java.io.OutputStream;

class HexEncoder {

  protected final byte[] encodingTable =
      {
          (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', (byte)'6', (byte)'7',
          (byte)'8', (byte)'9', (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f'
      };

  /*
  * set up the decoding table.
  */
  protected final byte[] decodingTable = new byte[128];

  protected void initialiseDecodingTable() {
    for (int i = 0; i < encodingTable.length; i++) {
      decodingTable[encodingTable[i]] = (byte)i;
    }

    decodingTable['A'] = decodingTable['a'];
    decodingTable['B'] = decodingTable['b'];
    decodingTable['C'] = decodingTable['c'];
    decodingTable['D'] = decodingTable['d'];
    decodingTable['E'] = decodingTable['e'];
    decodingTable['F'] = decodingTable['f'];
  }

  public HexEncoder() {
    initialiseDecodingTable();
  }

  /**
   * encode the input data producing a Hex output stream.
   *
   * @return the number of bytes produced.
   */
  public int encode(
      byte[] data,
      int off,
      int length,
      OutputStream out)
      throws IOException
  {
    for (int i = off; i < (off + length); i++) {
      int v = data[i] & 0xff;

      out.write(encodingTable[(v >>> 4)]);
      out.write(encodingTable[v & 0xf]);
    }

    return length * 2;
  }

  private boolean ignore(
      char c)
  {
    return (c == '\n' || c == '\r' || c == '\t' || c == ' ');
  }

  /**
   * decode the Hex encoded byte data writing it to the given output stream,
   * whitespace characters will be ignored.
   *
   * @return the number of bytes produced.
   */
  public int decode(
      byte[] data,
      int off,
      int length,
      OutputStream out)
      throws IOException
  {
    byte b1, b2;
    int outLen = 0;

    int end = off + length;

    while (end > off) {
      if (!ignore((char)data[end - 1])) {
        break;
      }

      end--;
    }

    int i = off;
    while (i < end) {
      while (i < end && ignore((char)data[i])) {
        i++;
      }

      b1 = decodingTable[data[i++]];

      while (i < end && ignore((char)data[i])) {
        i++;
      }

      b2 = decodingTable[data[i++]];

      out.write((b1 << 4) | b2);

      outLen++;
    }

    return outLen;
  }

  /**
   * decode the Hex encoded String data writing it to the given output stream,
   * whitespace characters will be ignored.
   *
   * @return the number of bytes produced.
   */
  public int decode(
      String data,
      OutputStream out)
      throws IOException
  {
    byte b1, b2;
    int length = 0;

    int end = data.length();

    while (end > 0) {
      if (!ignore(data.charAt(end - 1))) {
        break;
      }

      end--;
    }

    int i = 0;
    while (i < end) {
      while (i < end && ignore(data.charAt(i))) {
        i++;
      }

      b1 = decodingTable[data.charAt(i++)];

      while (i < end && ignore(data.charAt(i))) {
        i++;
      }

      b2 = decodingTable[data.charAt(i++)];

      out.write((b1 << 4) | b2);

      length++;
    }

    return length;
  }
}




Java Source Code List

org.emergent.android.weave.client.Base32.java
org.emergent.android.weave.client.Base64Encoder.java
org.emergent.android.weave.client.Base64.java
org.emergent.android.weave.client.BulkKeyCouplet.java
org.emergent.android.weave.client.Dbg.java
org.emergent.android.weave.client.HexEncoder.java
org.emergent.android.weave.client.Hex.java
org.emergent.android.weave.client.QueryParams.java
org.emergent.android.weave.client.QueryResult.java
org.emergent.android.weave.client.UserWeave.java
org.emergent.android.weave.client.WeaveAccountInfo.java
org.emergent.android.weave.client.WeaveBasicObject.java
org.emergent.android.weave.client.WeaveConstants.java
org.emergent.android.weave.client.WeaveCryptoUtil.java
org.emergent.android.weave.client.WeaveException.java
org.emergent.android.weave.client.WeaveFactory.java
org.emergent.android.weave.client.WeaveHeader.java
org.emergent.android.weave.client.WeaveResponse.java
org.emergent.android.weave.client.WeaveSSLSocketFactory.java
org.emergent.android.weave.client.WeaveTransport.java
org.emergent.android.weave.client.WeaveUtil.java
org.greendroid.QuickActionGrid.java
org.greendroid.QuickActionWidget.java
org.greendroid.QuickAction.java
org.zirco.controllers.Controller.java
org.zirco.events.EventConstants.java
org.zirco.events.EventController.java
org.zirco.events.IDownloadEventsListener.java
org.zirco.model.DbAdapter.java
org.zirco.model.UrlSuggestionItemComparator.java
org.zirco.model.adapters.BookmarksCursorAdapter.java
org.zirco.model.adapters.DownloadListAdapter.java
org.zirco.model.adapters.HistoryExpandableListAdapter.java
org.zirco.model.adapters.UrlSuggestionCursorAdapter.java
org.zirco.model.adapters.WeaveBookmarksCursorAdapter.java
org.zirco.model.items.BookmarkItem.java
org.zirco.model.items.DownloadItem.java
org.zirco.model.items.HistoryItem.java
org.zirco.model.items.UrlSuggestionItem.java
org.zirco.model.items.WeaveBookmarkItem.java
org.zirco.providers.BookmarksProviderWrapper.java
org.zirco.providers.WeaveColumns.java
org.zirco.providers.WeaveContentProvider.java
org.zirco.providers.ZircoBookmarksContentProvider.java
org.zirco.sync.ISyncListener.java
org.zirco.sync.WeaveSyncTask.java
org.zirco.ui.activities.AboutActivity.java
org.zirco.ui.activities.AdBlockerWhiteListActivity.java
org.zirco.ui.activities.BookmarksHistoryActivity.java
org.zirco.ui.activities.BookmarksListActivity.java
org.zirco.ui.activities.ChangelogActivity.java
org.zirco.ui.activities.DownloadsListActivity.java
org.zirco.ui.activities.EditBookmarkActivity.java
org.zirco.ui.activities.HistoryListActivity.java
org.zirco.ui.activities.IToolbarsContainer.java
org.zirco.ui.activities.MainActivity.java
org.zirco.ui.activities.MobileViewListActivity.java
org.zirco.ui.activities.WeaveBookmarksListActivity.java
org.zirco.ui.activities.preferences.BaseSpinnerCustomPreferenceActivity.java
org.zirco.ui.activities.preferences.HomepagePreferenceActivity.java
org.zirco.ui.activities.preferences.PreferencesActivity.java
org.zirco.ui.activities.preferences.SearchUrlPreferenceActivity.java
org.zirco.ui.activities.preferences.UserAgentPreferenceActivity.java
org.zirco.ui.activities.preferences.WeavePreferencesActivity.java
org.zirco.ui.activities.preferences.WeaveServerPreferenceActivity.java
org.zirco.ui.components.CustomWebViewClient.java
org.zirco.ui.components.CustomWebView.java
org.zirco.ui.runnables.DownloadRunnable.java
org.zirco.ui.runnables.FaviconUpdaterRunnable.java
org.zirco.ui.runnables.HideToolbarsRunnable.java
org.zirco.ui.runnables.HistoryUpdater.java
org.zirco.ui.runnables.XmlHistoryBookmarksExporter.java
org.zirco.ui.runnables.XmlHistoryBookmarksImporter.java
org.zirco.utils.AnimationManager.java
org.zirco.utils.ApplicationUtils.java
org.zirco.utils.Constants.java
org.zirco.utils.DateUtils.java
org.zirco.utils.IOUtils.java
org.zirco.utils.ProxyChangeReceiver.java
org.zirco.utils.ProxySettings.java
org.zirco.utils.UrlUtils.java