Exemplo n.º 1
0
		protected internal virtual string GetBitFlagDescription(int tagType, [NotNull] params object[] labels)
		{
			int? value = _directory.GetInteger(tagType);
			if (value == null)
			{
				return null;
			}
            IList<CharSequence> parts = new AList<CharSequence>();
			int bitIndex = 0;
			while (labels.Length > bitIndex)
			{
				object labelObj = labels[bitIndex];
				if (labelObj != null)
				{
					bool isBitSet = ((int)value & 1) == 1;
					if (labelObj is string[])
					{
						string[] labelPair = (string[])labelObj;
						System.Diagnostics.Debug.Assert((labelPair.Length == 2));
						parts.Add(labelPair[isBitSet ? 1 : 0]);
					}
					else
					{
						if (isBitSet && labelObj is string)
						{
							parts.Add((string)labelObj);
						}
					}
				}
				value >>= 1;
				bitIndex++;
			}
			return StringUtil.Join(parts.AsIterable(), ", ");
		}
		public virtual void TestJoinIterable()
		{
			IList<string> strings = new AList<string>();
			strings.Add("A");
			strings.Add("B");
			strings.Add("C");
			Sharpen.Tests.AreEqual("A;B;C", StringUtil.Join(strings.AsIterable(), ";"));
			Sharpen.Tests.AreEqual(string.Empty, StringUtil.Join(new AList<string>(), ";"));
		}
        public virtual void TestJoinIterable()
        {
            IList <string> strings = new AList <string>();

            strings.Add("A");
            strings.Add("B");
            strings.Add("C");
            Sharpen.Tests.AreEqual("A;B;C", StringUtil.Join(strings.AsIterable(), ";"));
            Sharpen.Tests.AreEqual(string.Empty, StringUtil.Join(new AList <string>(), ";"));
        }
Exemplo n.º 4
0
        public virtual void TestReadJpegSegmentWithNoExifData()
        {
            sbyte[] badExifData = new sbyte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            Com.Drew.Metadata.Metadata metadata = new Com.Drew.Metadata.Metadata();
            AList <sbyte[]>            segments = new AList <sbyte[]>();

            segments.Add(badExifData);
            new ExifReader().ReadJpegSegments(segments.AsIterable(), metadata, JpegSegmentType.App1);
            Sharpen.Tests.AreEqual(0, metadata.GetDirectoryCount());
            Sharpen.Tests.IsFalse(metadata.HasErrors());
        }
 public virtual void SetUp()
 {
     Com.Drew.Metadata.Metadata metadata = new Com.Drew.Metadata.Metadata();
     IList<sbyte[]> jpegSegments = new AList<sbyte[]>();
     jpegSegments.Add(FileUtil.ReadBytes("Tests/Data/withXmpAndIptc.jpg.app1.1"));
     new XmpReader().ReadJpegSegments(jpegSegments.AsIterable(), metadata, JpegSegmentType.App1);
     ICollection<XmpDirectory> xmpDirectories = metadata.GetDirectoriesOfType<XmpDirectory>();
     NUnit.Framework.Assert.IsNotNull(xmpDirectories);
     Sharpen.Tests.AreEqual(1, xmpDirectories.Count);
     _directory = xmpDirectories.Iterator().Next();
     Sharpen.Tests.IsFalse(_directory.HasErrors());
 }
Exemplo n.º 6
0
        public virtual void SetUp()
        {
            Com.Drew.Metadata.Metadata metadata     = new Com.Drew.Metadata.Metadata();
            IList <sbyte[]>            jpegSegments = new AList <sbyte[]>();

            jpegSegments.Add(FileUtil.ReadBytes("Tests/Data/withXmpAndIptc.jpg.app1.1"));
            new XmpReader().ReadJpegSegments(jpegSegments.AsIterable(), metadata, JpegSegmentType.App1);
            ICollection <XmpDirectory> xmpDirectories = metadata.GetDirectoriesOfType <XmpDirectory>();

            NUnit.Framework.Assert.IsNotNull(xmpDirectories);
            Sharpen.Tests.AreEqual(1, xmpDirectories.Count);
            _directory = xmpDirectories.Iterator().Next();
            Sharpen.Tests.IsFalse(_directory.HasErrors());
        }
		/// <exception cref="Com.Drew.Imaging.Png.PngProcessingException"/>
		/// <exception cref="System.IO.IOException"/>
		public virtual Iterable<PngChunk> Extract(SequentialReader reader, ICollection<PngChunkType> desiredChunkTypes)
		{
			//
			// PNG DATA STREAM
			//
			// Starts with a PNG SIGNATURE, followed by a sequence of CHUNKS.
			//
			// PNG SIGNATURE
			//
			//   Always composed of these bytes: 89 50 4E 47 0D 0A 1A 0A
			//
			// CHUNK
			//
			//   4 - length of the data field (unsigned, but always within 31 bytes), may be zero
			//   4 - chunk type, restricted to [65,90] and [97,122] (A-Za-z)
			//   * - data field
			//   4 - CRC calculated from chunk type and chunk data, but not length
			//
			// CHUNK TYPES
			//
			//   Critical Chunk Types:
			//
			//     IHDR - image header, always the first chunk in the data stream
			//     PLTE - palette table, associated with indexed PNG images
			//     IDAT - image data chunk, of which there may be many
			//     IEND - image trailer, always the last chunk in the data stream
			//
			//   Ancillary Chunk Types:
			//
			//     Transparency information:  tRNS
			//     Colour space information:  cHRM, gAMA, iCCP, sBIT, sRGB
			//     Textual information:       iTXt, tEXt, zTXt
			//     Miscellaneous information: bKGD, hIST, pHYs, sPLT
			//     Time information:          tIME
			//
			reader.SetMotorolaByteOrder(true);
			// network byte order
			if (!Arrays.Equals(PngSignatureBytes, reader.GetBytes(PngSignatureBytes.Length)))
			{
				throw new PngProcessingException("PNG signature mismatch");
			}
			bool seenImageHeader = false;
			bool seenImageTrailer = false;
			IList<PngChunk> chunks = new AList<PngChunk>();
			ICollection<PngChunkType> seenChunkTypes = new HashSet<PngChunkType>();
			while (!seenImageTrailer)
			{
				// Process the next chunk.
				int chunkDataLength = reader.GetInt32();
				PngChunkType chunkType = new PngChunkType(reader.GetBytes(4));
				sbyte[] chunkData = reader.GetBytes(chunkDataLength);
				// Skip the CRC bytes at the end of the chunk
				// TODO consider verifying the CRC value to determine if we're processing bad data
				reader.Skip(4);
				if (seenChunkTypes.Contains(chunkType) && !chunkType.AreMultipleAllowed())
				{
					throw new PngProcessingException(Sharpen.Extensions.StringFormat("Observed multiple instances of PNG chunk '%s', for which multiples are not allowed", chunkType));
				}
				if (chunkType.Equals(PngChunkType.Ihdr))
				{
					seenImageHeader = true;
				}
				else
				{
					if (!seenImageHeader)
					{
						throw new PngProcessingException(Sharpen.Extensions.StringFormat("First chunk should be '%s', but '%s' was observed", PngChunkType.Ihdr, chunkType));
					}
				}
				if (chunkType.Equals(PngChunkType.Iend))
				{
					seenImageTrailer = true;
				}
				if (desiredChunkTypes == null || desiredChunkTypes.Contains(chunkType))
				{
					chunks.Add(new PngChunk(chunkType, chunkData));
				}
				seenChunkTypes.Add(chunkType);
			}
			return chunks.AsIterable();
		}
Exemplo n.º 8
0
        /// <summary>
        /// Executes the
        /// <code>push</code>
        /// command with all the options and parameters
        /// collected by the setter methods of this class. Each instance of this
        /// class should only be used for one invocation of the command (means: one
        /// call to
        /// <see cref="Call()">Call()</see>
        /// )
        /// </summary>
        /// <returns>
        /// an iteration over
        /// <see cref="NGit.Transport.PushResult">NGit.Transport.PushResult</see>
        /// objects
        /// </returns>
        /// <exception cref="NGit.Api.Errors.InvalidRemoteException">when called with an invalid remote uri
        ///     </exception>
        /// <exception cref="NGit.Api.Errors.TransportException">when an error occurs with the transport
        /// </exception>
        /// <exception cref="NGit.Api.Errors.GitAPIException">NGit.Api.Errors.GitAPIException
        ///     </exception>
        public override Iterable <PushResult> Call()
        {
            CheckCallable();
            AList <PushResult> pushResults = new AList <PushResult>(3);

            try
            {
                if (refSpecs.IsEmpty())
                {
                    RemoteConfig config = new RemoteConfig(repo.GetConfig(), GetRemote());
                    Sharpen.Collections.AddAll(refSpecs, config.PushRefSpecs);
                }
                if (refSpecs.IsEmpty())
                {
                    Ref head = repo.GetRef(Constants.HEAD);
                    if (head != null && head.IsSymbolic())
                    {
                        refSpecs.AddItem(new RefSpec(head.GetLeaf().GetName()));
                    }
                }
                if (force)
                {
                    for (int i = 0; i < refSpecs.Count; i++)
                    {
                        refSpecs.Set(i, refSpecs[i].SetForceUpdate(true));
                    }
                }
                IList <NGit.Transport.Transport> transports;
                transports = NGit.Transport.Transport.OpenAll(repo, remote, NGit.Transport.Transport.Operation.PUSH
                                                              );
                foreach (NGit.Transport.Transport transport in transports)
                {
                    transport.SetPushThin(thin);
                    if (receivePack != null)
                    {
                        transport.SetOptionReceivePack(receivePack);
                    }
                    transport.SetDryRun(dryRun);
                    Configure(transport);
                    ICollection <RemoteRefUpdate> toPush = transport.FindRemoteRefUpdatesFor(refSpecs);
                    try
                    {
                        PushResult result = transport.Push(monitor, toPush);
                        pushResults.AddItem(result);
                    }
                    catch (NGit.Errors.TransportException e)
                    {
                        throw new NGit.Errors.TransportException(e.Message, e);
                    }
                    finally
                    {
                        transport.Close();
                    }
                }
            }
            catch (URISyntaxException)
            {
                throw new InvalidRemoteException(MessageFormat.Format(JGitText.Get().invalidRemote
                                                                      , remote));
            }
            catch (NGit.Errors.NotSupportedException e)
            {
                throw new JGitInternalException(JGitText.Get().exceptionCaughtDuringExecutionOfPushCommand
                                                , e);
            }
            catch (IOException e)
            {
                throw new JGitInternalException(JGitText.Get().exceptionCaughtDuringExecutionOfPushCommand
                                                , e);
            }
            return(pushResults.AsIterable());
        }
Exemplo n.º 9
0
        /// <summary>
        /// Executes the
        /// <code>push</code>
        /// command with all the options and parameters
        /// collected by the setter methods of this class. Each instance of this
        /// class should only be used for one invocation of the command (means: one
        /// call to
        /// <see cref="Call()">Call()</see>
        /// )
        /// </summary>
        /// <returns>
        /// an iteration over
        /// <see cref="NGit.Transport.PushResult">NGit.Transport.PushResult</see>
        /// objects
        /// </returns>
        /// <exception cref="NGit.Api.Errors.InvalidRemoteException">when called with an invalid remote uri
        ///     </exception>
        /// <exception cref="NGit.Api.Errors.JGitInternalException">
        /// a low-level exception of JGit has occurred. The original
        /// exception can be retrieved by calling
        /// <see cref="System.Exception.InnerException()">System.Exception.InnerException()</see>
        /// .
        /// </exception>
        public override Iterable <PushResult> Call()
        {
            CheckCallable();
            AList <PushResult> pushResults = new AList <PushResult>(3);

            try
            {
                if (force)
                {
                    IList <RefSpec> orig = new AList <RefSpec>(refSpecs);
                    refSpecs.Clear();
                    foreach (RefSpec spec in orig)
                    {
                        refSpecs.AddItem(spec.SetForceUpdate(true));
                    }
                }
                IList <NGit.Transport.Transport> transports;
                transports = NGit.Transport.Transport.OpenAll(repo, remote, NGit.Transport.Transport.Operation.PUSH
                                                              );
                foreach (NGit.Transport.Transport transport in transports)
                {
                    if (0 <= timeout)
                    {
                        transport.SetTimeout(timeout);
                    }
                    transport.SetPushThin(thin);
                    if (receivePack != null)
                    {
                        transport.SetOptionReceivePack(receivePack);
                    }
                    transport.SetDryRun(dryRun);
                    if (credentialsProvider != null)
                    {
                        transport.SetCredentialsProvider(credentialsProvider);
                    }
                    ICollection <RemoteRefUpdate> toPush = transport.FindRemoteRefUpdatesFor(refSpecs);
                    try
                    {
                        PushResult result = transport.Push(monitor, toPush);
                        pushResults.AddItem(result);
                    }
                    catch (TransportException e)
                    {
                        throw new JGitInternalException(JGitText.Get().exceptionCaughtDuringExecutionOfPushCommand
                                                        , e);
                    }
                    finally
                    {
                        transport.Close();
                    }
                }
            }
            catch (URISyntaxException)
            {
                throw new InvalidRemoteException(MessageFormat.Format(JGitText.Get().invalidRemote
                                                                      , remote));
            }
            catch (NotSupportedException e)
            {
                throw new JGitInternalException(JGitText.Get().exceptionCaughtDuringExecutionOfPushCommand
                                                , e);
            }
            catch (IOException e)
            {
                throw new JGitInternalException(JGitText.Get().exceptionCaughtDuringExecutionOfPushCommand
                                                , e);
            }
            return(pushResults.AsIterable());
        }
Exemplo n.º 10
0
        /// <exception cref="Com.Drew.Imaging.Png.PngProcessingException"/>
        /// <exception cref="System.IO.IOException"/>
        public virtual Iterable <PngChunk> Extract([NotNull] SequentialReader reader, [CanBeNull] ICollection <PngChunkType> desiredChunkTypes)
        {
            //
            // PNG DATA STREAM
            //
            // Starts with a PNG SIGNATURE, followed by a sequence of CHUNKS.
            //
            // PNG SIGNATURE
            //
            //   Always composed of these bytes: 89 50 4E 47 0D 0A 1A 0A
            //
            // CHUNK
            //
            //   4 - length of the data field (unsigned, but always within 31 bytes), may be zero
            //   4 - chunk type, restricted to [65,90] and [97,122] (A-Za-z)
            //   * - data field
            //   4 - CRC calculated from chunk type and chunk data, but not length
            //
            // CHUNK TYPES
            //
            //   Critical Chunk Types:
            //
            //     IHDR - image header, always the first chunk in the data stream
            //     PLTE - palette table, associated with indexed PNG images
            //     IDAT - image data chunk, of which there may be many
            //     IEND - image trailer, always the last chunk in the data stream
            //
            //   Ancillary Chunk Types:
            //
            //     Transparency information:  tRNS
            //     Colour space information:  cHRM, gAMA, iCCP, sBIT, sRGB
            //     Textual information:       iTXt, tEXt, zTXt
            //     Miscellaneous information: bKGD, hIST, pHYs, sPLT
            //     Time information:          tIME
            //
            reader.SetMotorolaByteOrder(true);
            // network byte order
            if (!Arrays.Equals(PngSignatureBytes, reader.GetBytes(PngSignatureBytes.Length)))
            {
                throw new PngProcessingException("PNG signature mismatch");
            }
            bool                       seenImageHeader  = false;
            bool                       seenImageTrailer = false;
            IList <PngChunk>           chunks           = new AList <PngChunk>();
            ICollection <PngChunkType> seenChunkTypes   = new HashSet <PngChunkType>();

            while (!seenImageTrailer)
            {
                // Process the next chunk.
                int          chunkDataLength = reader.GetInt32();
                PngChunkType chunkType       = new PngChunkType(reader.GetBytes(4));
                bool         willStoreChunk  = desiredChunkTypes == null || desiredChunkTypes.Contains(chunkType);
                sbyte[]      chunkData       = reader.GetBytes(chunkDataLength);
                // Skip the CRC bytes at the end of the chunk
                // TODO consider verifying the CRC value to determine if we're processing bad data
                reader.Skip(4);
                if (willStoreChunk && seenChunkTypes.Contains(chunkType) && !chunkType.AreMultipleAllowed())
                {
                    throw new PngProcessingException(Sharpen.Extensions.StringFormat("Observed multiple instances of PNG chunk '%s', for which multiples are not allowed", chunkType));
                }
                if (chunkType.Equals(PngChunkType.Ihdr))
                {
                    seenImageHeader = true;
                }
                else
                {
                    if (!seenImageHeader)
                    {
                        throw new PngProcessingException(Sharpen.Extensions.StringFormat("First chunk should be '%s', but '%s' was observed", PngChunkType.Ihdr, chunkType));
                    }
                }
                if (chunkType.Equals(PngChunkType.Iend))
                {
                    seenImageTrailer = true;
                }
                if (willStoreChunk)
                {
                    chunks.Add(new PngChunk(chunkType, chunkData));
                }
                seenChunkTypes.Add(chunkType);
            }
            return(chunks.AsIterable());
        }