Android Open Source - JiangHomeStyle_Android_Phone General Purpose Bit






From Project

Back to project page JiangHomeStyle_Android_Phone.

License

The source code is released under:

Apache License

If you think the Android project JiangHomeStyle_Android_Phone 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

/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *//from ww  w.  j  a  v a 2  s  . com
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */
package org.apache.tools.zip;

/**
 * Parser/encoder for the "general purpose bit" field in ZIP's local file and
 * central directory headers.
 * 
 * @since Ant 1.9.0
 */
public final class GeneralPurposeBit
{
  /**
   * Indicates that the file is encrypted.
   */
  private static final int ENCRYPTION_FLAG = 1 << 0;

  /**
   * Indicates that a data descriptor stored after the file contents will hold
   * CRC and size information.
   */
  private static final int DATA_DESCRIPTOR_FLAG = 1 << 3;

  /**
   * Indicates strong encryption.
   */
  private static final int STRONG_ENCRYPTION_FLAG = 1 << 6;

  /**
   * Indicates that filenames are written in utf-8.
   * 
   * <p>
   * The only reason this is public is that {@link ZipOutputStream#EFS_FLAG}
   * was public in several versions of Apache Ant and we needed a substitute
   * for it.
   * </p>
   */
  public static final int UFT8_NAMES_FLAG = 1 << 11;

  private boolean languageEncodingFlag = false;
  private boolean dataDescriptorFlag = false;
  private boolean encryptionFlag = false;
  private boolean strongEncryptionFlag = false;

  public GeneralPurposeBit()
  {
  }

  /**
   * whether the current entry uses UTF8 for file name and comment.
   */
  public boolean usesUTF8ForNames()
  {
    return languageEncodingFlag;
  }

  /**
   * whether the current entry will use UTF8 for file name and comment.
   */
  public void useUTF8ForNames(boolean b)
  {
    languageEncodingFlag = b;
  }

  /**
   * whether the current entry uses the data descriptor to store CRC and size
   * information
   */
  public boolean usesDataDescriptor()
  {
    return dataDescriptorFlag;
  }

  /**
   * whether the current entry will use the data descriptor to store CRC and
   * size information
   */
  public void useDataDescriptor(boolean b)
  {
    dataDescriptorFlag = b;
  }

  /**
   * whether the current entry is encrypted
   */
  public boolean usesEncryption()
  {
    return encryptionFlag;
  }

  /**
   * whether the current entry will be encrypted
   */
  public void useEncryption(boolean b)
  {
    encryptionFlag = b;
  }

  /**
   * whether the current entry is encrypted using strong encryption
   */
  public boolean usesStrongEncryption()
  {
    return encryptionFlag && strongEncryptionFlag;
  }

  /**
   * whether the current entry will be encrypted using strong encryption
   */
  public void useStrongEncryption(boolean b)
  {
    strongEncryptionFlag = b;
    if (b)
    {
      useEncryption(true);
    }
  }

  /**
   * Encodes the set bits in a form suitable for ZIP archives.
   */
  public byte[] encode()
  {
    return ZipShort.getBytes((dataDescriptorFlag ? DATA_DESCRIPTOR_FLAG : 0) | (languageEncodingFlag ? UFT8_NAMES_FLAG : 0)
        | (encryptionFlag ? ENCRYPTION_FLAG : 0) | (strongEncryptionFlag ? STRONG_ENCRYPTION_FLAG : 0));
  }

  /**
   * Parses the supported flags from the given archive data.
   * 
   * @param data
   *            local file header or a central directory entry.
   * @param offset
   *            offset at which the general purpose bit starts
   */
  public static GeneralPurposeBit parse(final byte[] data, final int offset)
  {
    final int generalPurposeFlag = ZipShort.getValue(data, offset);
    GeneralPurposeBit b = new GeneralPurposeBit();
    b.useDataDescriptor((generalPurposeFlag & DATA_DESCRIPTOR_FLAG) != 0);
    b.useUTF8ForNames((generalPurposeFlag & UFT8_NAMES_FLAG) != 0);
    b.useStrongEncryption((generalPurposeFlag & STRONG_ENCRYPTION_FLAG) != 0);
    b.useEncryption((generalPurposeFlag & ENCRYPTION_FLAG) != 0);
    return b;
  }

  @Override
  public int hashCode()
  {
    return 3 * (7 * (13 * (17 * (encryptionFlag ? 1 : 0) + (strongEncryptionFlag ? 1 : 0)) + (languageEncodingFlag ? 1 : 0)) + (dataDescriptorFlag ? 1
        : 0));
  }

  @Override
  public boolean equals(Object o)
  {
    if (!(o instanceof GeneralPurposeBit))
    {
      return false;
    }
    GeneralPurposeBit g = (GeneralPurposeBit) o;
    return g.encryptionFlag == encryptionFlag && g.strongEncryptionFlag == strongEncryptionFlag
        && g.languageEncodingFlag == languageEncodingFlag && g.dataDescriptorFlag == dataDescriptorFlag;
  }
}




Java Source Code List

com.cidesign.jianghomestylephone.DetailActivity.java
com.cidesign.jianghomestylephone.JiangActivity.java
com.cidesign.jianghomestylephone.MainActivity.java
com.cidesign.jianghomestylephone.SplashActivity.java
com.cidesign.jianghomestylephone.adapter.CommunityViewpagerAdapter.java
com.cidesign.jianghomestylephone.adapter.HumanityViewpagerAdapter.java
com.cidesign.jianghomestylephone.adapter.LandscapeViewpagerAdapter.java
com.cidesign.jianghomestylephone.adapter.LayoutCaculateAdapter.java
com.cidesign.jianghomestylephone.adapter.StoryViewpagerAdapter.java
com.cidesign.jianghomestylephone.async.AsyncDownTask.java
com.cidesign.jianghomestylephone.async.AsyncInitCommunityData.java
com.cidesign.jianghomestylephone.async.AsyncInitData.java
com.cidesign.jianghomestylephone.async.AsyncInitHomeData.java
com.cidesign.jianghomestylephone.async.AsyncInitHumanityData.java
com.cidesign.jianghomestylephone.async.AsyncInitLandscapeData.java
com.cidesign.jianghomestylephone.async.AsyncInitStoryData.java
com.cidesign.jianghomestylephone.db.DatabaseConfigUtil.java
com.cidesign.jianghomestylephone.db.DatabaseHelper.java
com.cidesign.jianghomestylephone.entity.ArticleEntity.java
com.cidesign.jianghomestylephone.entity.FileListEntity.java
com.cidesign.jianghomestylephone.entity.LayoutEntity.java
com.cidesign.jianghomestylephone.entity.RelativeLayoutRulesEntity.java
com.cidesign.jianghomestylephone.http.ArticalOperation.java
com.cidesign.jianghomestylephone.http.DownLoadThread.java
com.cidesign.jianghomestylephone.service.DownloadService.java
com.cidesign.jianghomestylephone.tools.CategoryDataLoadingLogic.java
com.cidesign.jianghomestylephone.tools.FileOperationTools.java
com.cidesign.jianghomestylephone.tools.JiangCategory.java
com.cidesign.jianghomestylephone.tools.LayoutMarginSetting.java
com.cidesign.jianghomestylephone.tools.LoadingDataFromDB.java
com.cidesign.jianghomestylephone.tools.LoadingImageTools.java
com.cidesign.jianghomestylephone.tools.MD5Tools.java
com.cidesign.jianghomestylephone.tools.StorageUtils.java
com.cidesign.jianghomestylephone.tools.TimeTools.java
com.cidesign.jianghomestylephone.tools.WidgetCache.java
com.cidesign.jianghomestylephone.tools.XmlParseTools.java
com.cidesign.jianghomestylephone.version.NetworkTool.java
com.cidesign.jianghomestylephone.version.VersionConfig.java
com.cidesign.jianghomestylephone.version.VersionUpdate.java
com.cidesign.jianghomestylephone.widget.CommunityRelativeLayout.java
com.cidesign.jianghomestylephone.widget.CustomScrollView.java
com.cidesign.jianghomestylephone.widget.HScrollViewTouchLogic.java
com.cidesign.jianghomestylephone.widget.HumanityRelativeLayout.java
com.cidesign.jianghomestylephone.widget.LandscapeRelativeLayout.java
com.cidesign.jianghomestylephone.widget.PopMenu.java
com.cidesign.jianghomestylephone.widget.StoryRelativeLayout.java
org.apache.tools.zip.AbstractUnicodeExtraField.java
org.apache.tools.zip.AsiExtraField.java
org.apache.tools.zip.CentralDirectoryParsingZipExtraField.java
org.apache.tools.zip.ExtraFieldUtils.java
org.apache.tools.zip.FallbackZipEncoding.java
org.apache.tools.zip.GeneralPurposeBit.java
org.apache.tools.zip.JarMarker.java
org.apache.tools.zip.NioZipEncoding.java
org.apache.tools.zip.Simple8BitZipEncoding.java
org.apache.tools.zip.UnicodeCommentExtraField.java
org.apache.tools.zip.UnicodePathExtraField.java
org.apache.tools.zip.UnixStat.java
org.apache.tools.zip.UnparseableExtraFieldData.java
org.apache.tools.zip.UnrecognizedExtraField.java
org.apache.tools.zip.UnsupportedZipFeatureException.java
org.apache.tools.zip.Zip64ExtendedInformationExtraField.java
org.apache.tools.zip.Zip64Mode.java
org.apache.tools.zip.Zip64RequiredException.java
org.apache.tools.zip.ZipConstants.java
org.apache.tools.zip.ZipEightByteInteger.java
org.apache.tools.zip.ZipEncodingHelper.java
org.apache.tools.zip.ZipEncoding.java
org.apache.tools.zip.ZipEntry.java
org.apache.tools.zip.ZipExtraField.java
org.apache.tools.zip.ZipFile.java
org.apache.tools.zip.ZipLong.java
org.apache.tools.zip.ZipOutputStream.java
org.apache.tools.zip.ZipShort.java
org.apache.tools.zip.ZipUtil.java