Пример #1
0
 private static void AddEntries(java.util.zip.ZipFile file, string rootDirectory, string[] newFiles, bool flattenHierarchy)
 {
     string destFileName = file.getName();
     string tempFileName = Path.GetTempFileName();
     ZipOutputStream destination = new ZipOutputStream(new FileOutputStream(tempFileName));
     try
     {
         CopyEntries(file, destination);
         if (newFiles != null)
         {
             foreach (string str3 in newFiles)
             {
                 string directoryName;
                 if (flattenHierarchy)
                 {
                     directoryName = Path.GetDirectoryName(str3);
                 }
                 else if (rootDirectory == null)
                 {
                     directoryName = Path.GetPathRoot(str3);
                 }
                 else
                 {
                     directoryName = rootDirectory;
                 }
                 directoryName = directoryName + @"\";
                 ZipEntry ze = new ZipEntry(str3.Remove(0, directoryName.Length));
                 ze.setMethod(8);
                 destination.putNextEntry(ze);
                 try
                 {
                     FileInputStream source = new FileInputStream(str3);
                     try
                     {
                         CopyStream(source, destination);
                     }
                     finally
                     {
                         source.close();
                     }
                 }
                 finally
                 {
                     destination.closeEntry();
                 }
             }
         }
     }
     finally
     {
         destination.close();
     }
     file.close();
     System.IO.File.Copy(tempFileName, destFileName, true);
     System.IO.File.Delete(tempFileName);
 }
Пример #2
0
		internal static void CloseSelector (java.nio.channels.Selector selector)
		{
			java.util.Set keys = selector.keys();
			java.util.Iterator it = keys.iterator();

			try
			{
				selector.close();
			}
			catch (Exception e)
			{
#if DEBUG
				Console.WriteLine("Caught exception during CloseSelector selector.close - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
			}

			while (it.hasNext()) 
			{
				java.nio.channels.SelectionKey key = (java.nio.channels.SelectionKey)it.next();
				Socket source = (Socket)key.attachment();
				key.cancel ();
				try
				{
					if (source.Blocking)
					{
						/*
							A channel must be placed into non-blocking mode before being registered 
							with a selector, and may not be returned to blocking mode until it has been 
							deregistered. So, I need set the channel back to the blocking mode, if it was
							in blocking mode before select operation
						*/
						source.Blocking = true;
					}
				}
				catch (Exception be)
				{
#if DEBUG
					Console.WriteLine("Caught exception during CloseSelector source.Blocking - {0}: {1}\n{2}", be.GetType(), be.Message, be.StackTrace);
#endif
				}
			}

			try
			{
				selector.close();
			}
			catch (Exception e)
			{
#if DEBUG
				Console.WriteLine("Caught exception during CloseSelector selector.close - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
			}
		}
Пример #3
0
 private static void RemoveEntries(java.util.zip.ZipFile file, string[] items)
 {
     string destFileName = file.getName();
     string tempFileName = Path.GetTempFileName();
     ZipOutputStream destination = new ZipOutputStream(new FileOutputStream(tempFileName));
     try
     {
         List<ZipEntry> zippedItems = GetZippedItems(file);
         List<string> list2 = new List<string>();
         foreach (ZipEntry entry in zippedItems)
         {
             bool flag = false;
             foreach (string str3 in items)
             {
                 if (str3 != entry.getName())
                 {
                     flag = true;
                 }
             }
             if (flag)
             {
                 list2.Add(entry.getName());
             }
         }
         CopyEntries(file, destination, list2.ToArray());
     }
     finally
     {
         destination.close();
     }
     file.close();
     System.IO.File.Copy(tempFileName, destFileName, true);
     System.IO.File.Delete(tempFileName);
 }
Пример #4
0
		/// <summary>Returns a byte[] containing the remainder of 'in', closing it when done.
		/// 	</summary>
		/// <remarks>Returns a byte[] containing the remainder of 'in', closing it when done.
		/// 	</remarks>
		/// <exception cref="System.IO.IOException"></exception>
		public static byte[] readFully(java.io.InputStream @in)
		{
			try
			{
				return readFullyNoClose(@in);
			}
			finally
			{
				@in.close();
			}
		}
Пример #5
0
		/// <summary>Returns the remainder of 'reader' as a string, closing it when done.</summary>
		/// <remarks>Returns the remainder of 'reader' as a string, closing it when done.</remarks>
		/// <exception cref="System.IO.IOException"></exception>
		public static string readFully(java.io.Reader reader)
		{
			try
			{
				java.io.StringWriter writer = new java.io.StringWriter();
				char[] buffer = new char[1024];
				int count;
				while ((count = reader.read(buffer)) != -1)
				{
					writer.write(buffer, 0, count);
				}
				return writer.ToString();
			}
			finally
			{
				reader.close();
			}
		}
 /// <summary>
 /// Writes a stream of bytes representing an audio file of the file type
 /// indicated to the output stream provided.
 /// </summary>
 /// <remarks>
 /// Writes a stream of bytes representing an audio file of the file type
 /// indicated to the output stream provided.
 /// </remarks>
 /// <param name="stream">
 /// - the audio input stream containing audio data to be written
 /// to the output stream.
 /// </param>
 /// <param name="out">- stream to which the file data should be written.</param>
 /// <returns>the number of bytes written to the output stream.</returns>
 /// <exception>
 /// IOException
 /// - if an I/O exception occurs.
 /// </exception>
 /// <exception cref="System.IO.IOException"></exception>
 private int write(javax.sound.sampled.AudioInputStream stream, java.io.OutputStream
     @out)
 {
     byte[] data = new byte[2048];
     int read = 0;
     int temp;
     while ((temp = stream.read(data, 0, 2048)) > 0)
     {
         @out.write(data, 0, temp);
         read += temp;
     }
     @out.flush();
     @out.close();
     return read;
 }