Пример #1
0
 public override void saveImage(ui.Image image, java.io.OutputStream response, java.lang.String format, float quality)
 {
     CanvasBitmapFileFormat fileFormat = CanvasBitmapFileFormat.Png;
     if (format.equals(_fFORMAT_1JPEG))
     {
         fileFormat = CanvasBitmapFileFormat.Jpeg;
     }
     CodenameOneImage img = (CodenameOneImage)image.getImage();
     CanvasBitmap cb = img.image;
     InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream();
     cb.SaveAsync(ms, fileFormat, quality).AsTask().ConfigureAwait(false).GetAwaiter().GetResult(); ;
     ms.Seek(0);
     byte[] buf = new byte[ms.Size];
     DataReader dr = new DataReader(ms);
     dr.LoadAsync((uint)ms.Size).AsTask().ConfigureAwait(false).GetAwaiter().GetResult(); ;
     dr.ReadBytes(buf);
     response.write(new _nArrayAdapter<sbyte>(SilverlightImplementation.toSByteArray(buf)));
 }
Пример #2
0
 protected override void saveImage(ui.Image image, java.io.OutputStream response, string format, float quality)
 {
     CanvasBitmapFileFormat fileFormat = CanvasBitmapFileFormat.Png;
     if (format.Equals(FORMAT_JPEG))
     {
         fileFormat = CanvasBitmapFileFormat.Jpeg;
     }
     CodenameOneImage img = (CodenameOneImage)image.getImage();
     CanvasBitmap cb = img.image;
     InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream();
     cb.SaveAsync(ms, fileFormat, quality).AsTask().ConfigureAwait(false).GetAwaiter().GetResult(); ;
     ms.Seek(0);
     byte[] buf = new byte[ms.Size];
     DataReader dr = new DataReader(ms);
     dr.LoadAsync((uint)ms.Size).AsTask().ConfigureAwait(false).GetAwaiter().GetResult(); ;
     dr.ReadBytes(buf);
     response.write(buf);
 }
Пример #3
0
 public override void save(java.io.InputStream image, java.io.OutputStream response, string format, int width, int height, float quality)
 {
     CanvasBitmapFileFormat fileFormat = CanvasBitmapFileFormat.Png;
     if (format.Equals(FORMAT_JPEG))
     {
         fileFormat = CanvasBitmapFileFormat.Jpeg;
     }
     CodenameOneImage img = (CodenameOneImage)SilverlightImplementation.instance.createImage(image);
     CodenameOneImage scaledImage = (CodenameOneImage)SilverlightImplementation.instance.scale(img, width, height);
     InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream();
     scaledImage.image.SaveAsync(ms, fileFormat, quality).AsTask().ConfigureAwait(false).GetAwaiter().GetResult();
     ms.Seek(0);
     byte[] buf = new byte[ms.Size];
     DataReader dr = new DataReader(ms);
     dr.LoadAsync((uint)ms.Size).AsTask().ConfigureAwait(false).GetAwaiter().GetResult();
     dr.ReadBytes(buf);
     response.write(buf);
 }
Пример #4
0
        public static void rewrite(java.io.Reader content, Uri source,
                                   Dictionary<String, IHtmlTagTransformer> transformers, java.io.Writer writer)
        {
            CharProducer producer = CharProducer.Factory.create(content, new InputSource(new java.net.URI(source.ToString())));
            HtmlLexer lexer = new HtmlLexer(producer);
            try
            {
                Token lastToken = null;
                Token currentTag = null;
                IHtmlTagTransformer currentTransformer = null;
                bool tagChanged;
                while (lexer.hasNext())
                {
                    tagChanged = false;
                    Token token = lexer.next() as Token;
                    if (token.type == HtmlTokenType.IGNORABLE)
                    {
                        continue;
                    }
                    if (token.type == HtmlTokenType.TAGBEGIN)
                    {
                        currentTag = token;
                        tagChanged = true;
                    }
                    if (tagChanged)
                    {
                        if (currentTransformer == null)
                        {
                            transformers.TryGetValue(currentTag.toString().Substring(1).ToLower(), out currentTransformer);
                        }
                        else
                        {
                            if (!currentTransformer.acceptNextTag(currentTag))
                            {
                                writer.write(currentTransformer.close());
                                transformers.TryGetValue(currentTag.toString().Substring(1).ToLower(), out currentTransformer);
                            }
                        }
                    }
                    if (currentTransformer == null)
                    {
                        writer.write(producePreTokenSeparator(token, lastToken));
                        writer.write(token.toString());
                        writer.write(producePostTokenSeparator(token, lastToken));
                    }
                    else
                    {
                        currentTransformer.accept(token, lastToken);
                    }
                    if (token.type == HtmlTokenType.TAGEND)
                    {
                        currentTag = null;
                    }
                    lastToken = token;
                }
                if (currentTransformer != null)
                {
                    writer.write(currentTransformer.close());
                }
                writer.flush();
            }
            catch (Exception pe)
            {
                throw pe;
            }

        }
Пример #5
0
        private void saveStreamToZip(string name, System.IO.Stream data, java.util.zip.ZipOutputStream zos)
        {
            java.util.zip.ZipEntry ze = new java.util.zip.ZipEntry(name);
            zos.putNextEntry(ze);

            byte[] buffer = new byte[1024];
            int ReadBytes;
            while ((ReadBytes = data.Read(buffer, 0, 1024)) > 0)
                try
                {
                    byte[] b2 = new byte[ReadBytes];
                    for (int i = 0; i < ReadBytes; i++) b2[i] = (byte)buffer[i];
                    zos.write(b2, 0, ReadBytes);
                }
                catch (System.IO.IOException e) {
                    File.AppendAllText("log_SAve.txt", DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + ": " + name + Environment.NewLine);
                    break;
                }

            zos.closeEntry();
        }
Пример #6
0
        private bool AddToZip(java.io.FileOutputStream fos, java.util.zip.ZipOutputStream zos, string sourceFile, string destName)
        {
            try
            {

                Thread.Sleep(6000);
                java.io.FileInputStream fis = new java.io.FileInputStream(sourceFile);
                java.util.zip.ZipEntry ze = new java.util.zip.ZipEntry(destName);
                zos.putNextEntry(ze);

                byte[] buffer = new byte[1024];
                int len;
                while ((len = fis.read(buffer)) >= 0)
                {
                    zos.write(buffer, 0, len);
                }
                zos.closeEntry();
                fis.close();
            }
            catch (Exception)
            {
                File.AppendAllText("log_save.txt", DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + ": " + sourceFile + Environment.NewLine);
                AddToZip( fos,  zos,  sourceFile,  destName);
            }

            return true;
        }
Пример #7
0
 public static List<String> rewrite(java.io.Reader content, Uri source,
                                    ILinkRewriter rewriter, java.io.Writer writer, bool extractImports)
 {
     List<String> imports = new List<string>();
     CharProducer producer = CharProducer.Factory.create(content,
                                                         new InputSource(new java.net.URI(source.ToString())));
     CssLexer lexer = new CssLexer(producer);
     try
     {
         bool inImport = false;
         while (lexer.hasNext())
         {
             Token token = lexer.next();
             if (extractImports)
             {
                 if (token.type == CssTokenType.SYMBOL && token.text.ToLower().Equals("@import"))
                 {
                     inImport = true;
                     continue;
                 }
                 if (inImport)
                 {
                     if (token.type == CssTokenType.URI)
                     {
                         Match matcher = urlMatcher.Match(token.text);
                         if (matcher.Success)
                         {
                             imports.Add(matcher.Groups[2].Value.Trim());
                         }
                     }
                     else if (token.type != CssTokenType.SPACE && token.type != CssTokenType.PUNCTUATION)
                     {
                         inImport = false;
                     }
                 }
                 if (!inImport)
                 {
                     writer.write(token.text);
                 }
             }
             else
             {
                 if (token.type == CssTokenType.URI)
                 {
                     writer.write(rewriteLink(token, source, rewriter));
                     continue;
                 }
                 writer.write(token.text);
             }
         }
         writer.flush();
     }
     catch (ParseException pe)
     {
         pe.printStackTrace();
     }
     catch (Exception ioe)
     {
         throw ioe;
     }
     return imports;
 }
Пример #8
0
			public void writeRequest(java.io.OutputStream output)
			{
				if(_out != null)
					_buffer = _out.toByteArray();
				if(_buffer != null)
				{
					output.write(_buffer, 0, _buffer.Length);
					_out = null;
				}
				else throw new ApplicationException();
			}
Пример #9
0
 private void writeObject(java.io.ObjectOutputStream oos)
 {
     if (m_modelData != null)
     {
         oos.writeInt(3);
         oos.writeInt(m_modelData.Length);
         oos.write(m_modelData, 0, m_modelData.Length);
         oos.writeBoolean(m_mustValue.HasValue);
         oos.writeInt(m_mustValue.HasValue ? m_mustValue.Value : 0);
         oos.writeDouble(m_delta.Value);
     }
 }
Пример #10
0
		/// <summary>
		/// Writes the contents of this
		/// <code>CharArrayWriter</code>
		/// to another
		/// <code>Writer</code>
		/// . The output is all the characters that have been written to the
		/// receiver since the last reset or since it was created.
		/// </summary>
		/// <param name="out">
		/// the non-null
		/// <code>Writer</code>
		/// on which to write the contents.
		/// </param>
		/// <exception cref="System.ArgumentNullException">
		/// if
		/// <code>out</code>
		/// is
		/// <code>null</code>
		/// .
		/// </exception>
		/// <exception cref="IOException">if an error occurs attempting to write out the contents.
		/// 	</exception>
		/// <exception cref="System.IO.IOException"></exception>
		public virtual void writeTo(java.io.Writer @out)
		{
			lock (@lock)
			{
				@out.write(buf, 0, count);
			}
		}
Пример #11
0
 /// <summary>Writes a Little-endian int.</summary>
 /// <remarks>Writes a Little-endian int.</remarks>
 /// <param name="os">- the output stream to write to.</param>
 /// <param name="v">- the value to write.</param>
 /// <exception>IOException</exception>
 /// <exception cref="System.IO.IOException"></exception>
 public static void writeInt(java.io.OutputStream os, int v)
 {
     if (System.BitConverter.IsLittleEndian)
     {
         os.write(System.BitConverter.GetBytes(v));
     }
     else
     {
         os.write(unchecked((int)(0xff)) & v);
         os.write(unchecked((int)(0xff)) & ((v) >> (8 & 0x1f)));
         os.write(unchecked((int)(0xff)) & ((v) >> (16 & 0x1f)));
         os.write(unchecked((int)(0xff)) & ((v) >> (24 & 0x1f)));
     }
 }
Пример #12
0
		/// <summary>Implements OutputStream.write(int) in terms of OutputStream.write(byte[], int, int).
		/// 	</summary>
		/// <remarks>
		/// Implements OutputStream.write(int) in terms of OutputStream.write(byte[], int, int).
		/// OutputStream assumes that you implement OutputStream.write(int) and provides default
		/// implementations of the others, but often the opposite is more efficient.
		/// </remarks>
		/// <exception cref="System.IO.IOException"></exception>
		public static void writeSingleByte(java.io.OutputStream @out, int b)
		{
			byte[] buffer = new byte[1];
			buffer[0] = unchecked((byte)(b & unchecked((int)(0xff))));
			@out.write(buffer);
		}
Пример #13
0
		/// <summary>
		/// Copies all of the bytes from
		/// <code>in</code>
		/// to
		/// <code>out</code>
		/// . Neither stream is closed.
		/// Returns the total number of bytes transferred.
		/// </summary>
		/// <exception cref="System.IO.IOException"></exception>
		public static int copy(java.io.InputStream @in, java.io.OutputStream @out)
		{
			int total = 0;
			byte[] buffer = new byte[8192];
			int c;
			while ((c = @in.read(buffer)) != -1)
			{
				total += c;
				@out.write(buffer, 0, c);
			}
			return total;
		}
 /// <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;
 }