예제 #1
0
        public void Zip(string zipFileName, string[] sourceFile)
        {
            FileOutputStream filOpStrm = new FileOutputStream(zipFileName);
            ZipOutputStream  zipOpStrm = new ZipOutputStream(filOpStrm);
            FileInputStream  filIpStrm = null;

            foreach (string strFilName  in sourceFile)
            {
                filIpStrm = new FileInputStream(strFilName);
                ZipEntry ze = new  ZipEntry(Path.GetFileName(strFilName));
                zipOpStrm.putNextEntry(ze);
                sbyte[] buffer = new
                                 sbyte[1024];
                int len = 0;
                while ((len =

                            filIpStrm.read(buffer)) >= 0)
                {
                    zipOpStrm.write(buffer, 0, len);
                }
            }
            zipOpStrm.closeEntry();
            filIpStrm.close();
            zipOpStrm.close();
            filOpStrm.close();
        }
예제 #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private static void copyFile(java.io.File src, java.io.File dst) throws java.io.IOException
        private static void copyFile(File src, File dst)
        {
            InputStream  @in  = new FileInputStream(src);
            OutputStream @out = new FileOutputStream(dst);
            int          len;

            while ((len = @in.read(copyBuffer)) > 0)
            {
                @out.write(copyBuffer, 0, len);
            }
            @in.close();
            @out.close();
        }
예제 #3
0
        private bool Method2(int arg)
        {
            if (arg == 0)
            {
                int count = 10;
            }
            FileInputStream stream         = new FileInputStream("Test");
            int             count_Renamed1 = Float.floatToIntBits(10f);

            byte[] buffer = new byte[count_Renamed1];
            stream.read(buffer);
            java.lang.reflect.Field f = null;
            return(Modifier.isTransient(f.getModifiers()));
        }
예제 #4
0
        private void addEntry(ZipOutputStream zipStream, String root, File file)
        {
            if (file.isHidden())
            {
                return;
            }
            var name     = root + file.getName();
            var zipEntry = new ZipEntry(name);

            zipStream.putNextEntry(zipEntry);
            var buffer      = new byte[4096];
            var inputStream = new FileInputStream(file);
            int read;

            while ((read = inputStream.read(buffer)) != -1)
            {
                zipStream.write(buffer, 0, read);
            }
        }
            internal CTLUtterance(BatchNISTRecognizer batchNISTRecognizer, string text, string text2)
            {
                this_0    = batchNISTRecognizer;
                this.@ref = text2;
                string[] array = String.instancehelper_split(text, " ");
                if (array.Length != 4)
                {
                    string text3 = new StringBuilder().append("CTL Syntax Error: ").append(text).toString();

                    throw new BatchNISTRecognizer.CTLException(batchNISTRecognizer, text3);
                }
                this.startOffset = Integer.parseInt(array[1]);
                this.endOffset   = Integer.parseInt(array[2]);
                this.name        = array[3];
                this.data        = new byte[(this.endOffset - this.startOffset) * batchNISTRecognizer.bytesPerFrame];
                int num = String.instancehelper_indexOf(array[0], 46);

                this.file = array[0];
                if (num >= 0)
                {
                    this.file = String.instancehelper_substring(this.file, 0, num);
                }
                this.file = new StringBuilder().append(batchNISTRecognizer.dataDir).append('/').append(this.file).append(".raw").toString();
                try
                {
                    FileInputStream fileInputStream = new FileInputStream(this.file);
                    fileInputStream.skip((long)(this.startOffset * batchNISTRecognizer.bytesPerFrame));
                    if (fileInputStream.read(this.data) != this.data.Length)
                    {
                        fileInputStream.close();
                        string text4 = new StringBuilder().append("Unable to read ").append(this.data.Length).append(" bytes of utterance ").append(this.name).toString();

                        throw new BatchNISTRecognizer.CTLException(batchNISTRecognizer, text4);
                    }
                    fileInputStream.close();
                }
                catch (IOException ex)
                {
                    throw new BatchNISTRecognizer.CTLException(batchNISTRecognizer, new StringBuilder().append("Unable to read utterance ").append(this.name).append(": ").append(Throwable.instancehelper_getMessage(ex)).toString());
                }
            }
예제 #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static java.util.List<MNISTImage> loadDigitImages(String labelFileName, String imageFileName) throws java.io.IOException
        public static List <MNISTImage> loadDigitImages(string labelFileName, string imageFileName)
        {
            List <MNISTImage> images = new List <MNISTImage>();

            ByteArrayOutputStream labelBuffer      = new ByteArrayOutputStream();
            ByteArrayOutputStream imageBuffer      = new ByteArrayOutputStream();
            InputStream           labelInputStream = new FileInputStream(labelFileName);
            InputStream           imageInputStream = new FileInputStream(imageFileName);

            /*	InputStream labelInputStream = MNISTDataSet.class.getResourceAsStream(labelFileName);
             *      InputStream imageInputStream = MNISTDataSet.class.getResourceAsStream(imageFileName);*/

            int read;

            sbyte[] buffer = new sbyte[16384];

            while ((read = labelInputStream.read(buffer, 0, buffer.Length)) != -1)
            {
                labelBuffer.write(buffer, 0, read);
            }

            labelBuffer.flush();

            while ((read = imageInputStream.read(buffer, 0, buffer.Length)) != -1)
            {
                imageBuffer.write(buffer, 0, read);
            }

            imageBuffer.flush();

            sbyte[] labelBytes = labelBuffer.toByteArray();
            sbyte[] imageBytes = imageBuffer.toByteArray();

            sbyte[] labelMagic = Arrays.copyOfRange(labelBytes, 0, OFFSET_SIZE);
            sbyte[] imageMagic = Arrays.copyOfRange(imageBytes, 0, OFFSET_SIZE);

            if (ByteBuffer.wrap(labelMagic).Int != LABEL_MAGIC)
            {
                throw new IOException("Bad magic number in label file!");
            }

            if (ByteBuffer.wrap(imageMagic).Int != IMAGE_MAGIC)
            {
                throw new IOException("Bad magic number in image file!");
            }

            int numberOfLabels = ByteBuffer.wrap(Arrays.copyOfRange(labelBytes, NUMBER_ITEMS_OFFSET, NUMBER_ITEMS_OFFSET + ITEMS_SIZE)).Int;
            int numberOfImages = ByteBuffer.wrap(Arrays.copyOfRange(imageBytes, NUMBER_ITEMS_OFFSET, NUMBER_ITEMS_OFFSET + ITEMS_SIZE)).Int;

            if (numberOfImages != numberOfLabels)
            {
                throw new IOException("The number of labels and images do not match!");
            }

            int numRows = ByteBuffer.wrap(Arrays.copyOfRange(imageBytes, NUMBER_OF_ROWS_OFFSET, NUMBER_OF_ROWS_OFFSET + ROWS_SIZE)).Int;
            int numCols = ByteBuffer.wrap(Arrays.copyOfRange(imageBytes, NUMBER_OF_COLUMNS_OFFSET, NUMBER_OF_COLUMNS_OFFSET + COLUMNS_SIZE)).Int;

            if (numRows != ROWS && numCols != COLUMNS)
            {
                throw new IOException("Bad image. Rows and columns do not equal " + ROWS + "x" + COLUMNS);
            }

            for (int i = 0; i < numberOfLabels; i++)
            {
                int     label     = labelBytes[OFFSET_SIZE + ITEMS_SIZE + i];
                sbyte[] imageData = Arrays.copyOfRange(imageBytes, (i * IMAGE_SIZE) + IMAGE_OFFSET, (i * IMAGE_SIZE) + IMAGE_OFFSET + IMAGE_SIZE);

                images.Add(new MNISTImage(label, imageData));
            }

            return(images);
        }
예제 #7
0
        public int run(String[] arguments)
        {
            sourceFiles.clear();
            if (!handleArguments(arguments))
            {
                return(1);
            }

            var t0 = System.nanoTime();

            try {
                var results   = new Compiler().compileFromFiles(parameters, sourceFiles.toArray(new File[sourceFiles.size()]));
                var hasErrors = false;
                foreach (var error in results.Errors)
                {
                    var filename = error.Filename;
                    if (filename != null)
                    {
                        System.out.print(new File(error.Filename).getAbsolutePath());
                    }
                    else
                    {
                        System.out.print("Unknown source");
                    }
                    if (error.Line > 0)
                    {
                        System.out.print(" (");
                        System.out.print(error.Line);
                        if (error.Column > 0)
                        {
                            System.out.print(", ");
                            System.out.print(error.Column);
                        }
                        System.out.print(")");
                    }
                    if (error.Level == 0)
                    {
                        hasErrors = true;
                        System.out.print(" error ");
                    }
                    else
                    {
                        System.out.print(" warning ");
                    }
                    System.out.print(error.Id);
                    System.out.print(": ");
                    System.out.println(error.Message);
                }
                if (!hasErrors)
                {
                    var outputFile = new File(outputPath);
                    if (outputFile.isDirectory() || outputPath.endsWith("\\") || outputPath.endsWith("/"))
                    {
                        foreach (var e in results.ClassFiles.entrySet())
                        {
                            var file = new File(outputFile, e.Key.replace('.', '/') + ".class");
                            var dir  = file.getParentFile();
                            if (!dir.exists())
                            {
                                dir.mkdirs();
                            }
                            using (var s = new FileOutputStream(file)) {
                                s.write(e.Value);
                            }
                        }
                    }
                    else
                    {
                        var destination = outputPath;
                        if (PathHelper.getExtension(destination).length() == 0)
                        {
                            destination += ".jar";
                        }
                        using (var zipStream = new ZipOutputStream(new FileOutputStream(destination))) {
                            if (manifestPath != null)
                            {
                                var zipEntry = new ZipEntry("META-INF/MANIFEST.MF");
                                zipStream.putNextEntry(zipEntry);
                                var buffer      = new byte[4096];
                                var inputStream = new FileInputStream(manifestPath);
                                int read;
                                while ((read = inputStream.read(buffer)) != -1)
                                {
                                    zipStream.write(buffer, 0, read);
                                }
                                inputStream.close();
                            }
                            if (resourcesPath != null)
                            {
                                var rootDir = new File(resourcesPath);
                                foreach (var content in rootDir.list())
                                {
                                    var file = new File(rootDir, content);
                                    if (file.isDirectory())
                                    {
                                        exploreDirectory(zipStream, "", file);
                                    }
                                    else
                                    {
                                        addEntry(zipStream, "", file);
                                    }
                                }
                            }
                            foreach (var e in results.ClassFiles.entrySet())
                            {
                                var zipEntry = new ZipEntry(e.Key.replace('.', '/') + ".class");
                                zipStream.putNextEntry(zipEntry);
                                zipStream.write(e.Value);
                            }
                        }
                    }
                    System.out.println();
                    System.out.println(String.format("%d class(es) successfully generated in %.2fs",
                                                     results.classFiles.size(), (System.nanoTime() - t0) / 1e9));
                    return(0);
                }
                else
                {
                    System.out.println();
                    System.out.println("Compilation failed");
                    return(1);
                }
            } catch (TypeLoadException e) {
                System.out.println("Cannot find type " + e.TypeName + ". The class is missing from the classpath.");
                System.out.println("Compilation failed");
                return(1);
            }
        }
예제 #8
0
        static void ClicpFont(Options option)
        {
            try
            {
                string subString = System.IO.File.ReadAllText(option.subFile);

                var             oriFile     = new File(option.srcFont);
                var             newFile     = new File(option.tarFont);
                FontFactory     fontFactory = FontFactory.getInstance();
                FileInputStream fileStream  = new FileInputStream(oriFile);
                byte[]          bytes       = new byte[(int)oriFile.length()];
                fileStream.read(bytes);
                Font[] fonts = null;
                fonts = fontFactory.loadFonts(bytes);
                Font      font1     = fonts[0];
                ArrayList arrayList = new ArrayList();
                arrayList.add(CMapTable.CMapId.WINDOWS_BMP);
                Object object2 = null;

                Font   font2 = font1;
                Object object3;
                if (subString.Length > 0)
                {
                    object2 = new RenumberingSubsetter(font2, fontFactory);
                    ((Subsetter)object2).setCMaps(arrayList, 1);
                    object3 = (Object)GlyphCoverage.getGlyphCoverage(font1, subString);
                    ((Subsetter)object2).setGlyphs((List)object3);
                    var hashSet = new HashSet();
                    hashSet.add(Integer.valueOf(Tag.GDEF));
                    hashSet.add(Integer.valueOf(Tag.GPOS));
                    hashSet.add(Integer.valueOf(Tag.GSUB));
                    hashSet.add(Integer.valueOf(Tag.kern));
                    hashSet.add(Integer.valueOf(Tag.hdmx));
                    hashSet.add(Integer.valueOf(Tag.vmtx));
                    hashSet.add(Integer.valueOf(Tag.VDMX));
                    hashSet.add(Integer.valueOf(Tag.LTSH));
                    hashSet.add(Integer.valueOf(Tag.DSIG));
                    hashSet.add(Integer.valueOf(Tag.intValue(new byte[] { 109, 111, 114, 116 })));
                    hashSet.add(Integer.valueOf(Tag.intValue(new byte[] { 109, 111, 114, 120 })));
                    ((Subsetter)object2).setRemoveTables(hashSet);
                    font2 = ((Subsetter)object2).subset().build();
                }
                if (strip)
                {
                    object2 = new HintStripper(font2, fontFactory);
                    object3 = new HashSet();
                    ((Set)object3).add(Integer.valueOf(Tag.fpgm));
                    ((Set)object3).add(Integer.valueOf(Tag.prep));
                    ((Set)object3).add(Integer.valueOf(Tag.cvt));
                    ((Set)object3).add(Integer.valueOf(Tag.hdmx));
                    ((Set)object3).add(Integer.valueOf(Tag.VDMX));
                    ((Set)object3).add(Integer.valueOf(Tag.LTSH));
                    ((Set)object3).add(Integer.valueOf(Tag.DSIG));
                    ((Subsetter)object2).setRemoveTables((Set)object3);
                    font2 = ((Subsetter)object2).subset().build();
                }
                object2 = new FileOutputStream(newFile);
                if (woff)
                {
                    object3 = new WoffWriter().convert(font2);
                    ((WritableFontData)object3).copyTo((OutputStream)object2);
                }
                else if (eot)
                {
                    object3 = new EOTWriter(mtx).convert(font2);
                    ((WritableFontData)object3).copyTo((OutputStream)object2);
                }
                else
                {
                    fontFactory.serializeFont(font2, (OutputStream)object2);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
예제 #9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private static void copyFile(java.io.File src, java.io.File dst) throws java.io.IOException
	  private static void copyFile(File src, File dst)
	  {
		InputStream @in = new FileInputStream(src);
		OutputStream @out = new FileOutputStream(dst);
		int len;
		while ((len = @in.read(copyBuffer)) > 0)
		{
		  @out.write(copyBuffer, 0, len);
		}
		@in.close();
		@out.close();
	  }