当前位置: 首页>>代码示例>>Java>>正文


Java JarInputStream.read方法代码示例

本文整理汇总了Java中java.util.jar.JarInputStream.read方法的典型用法代码示例。如果您正苦于以下问题:Java JarInputStream.read方法的具体用法?Java JarInputStream.read怎么用?Java JarInputStream.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.jar.JarInputStream的用法示例。


在下文中一共展示了JarInputStream.read方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: copyJarFile

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
static void copyJarFile(JarInputStream in, JarOutputStream out) throws IOException {
    if (in.getManifest() != null) {
        ZipEntry me = new ZipEntry(JarFile.MANIFEST_NAME);
        out.putNextEntry(me);
        in.getManifest().write(out);
        out.closeEntry();
    }
    byte[] buffer = new byte[1 << 14];
    for (JarEntry je; (je = in.getNextJarEntry()) != null; ) {
        out.putNextEntry(je);
        for (int nr; 0 < (nr = in.read(buffer)); ) {
            out.write(buffer, 0, nr);
        }
    }
    in.close();
    markJarFile(out);  // add PACK200 comment
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:Utils.java

示例2: pakBestandUit

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
private void pakBestandUit(final JarInputStream archiefStream, final File archiefBestand) throws IOException {
    final File parentBestand =
            new File(archiefBestand.getAbsolutePath().substring(0, archiefBestand.getAbsolutePath().lastIndexOf(File.separator)));
    parentBestand.mkdirs();
    if (archiefBestand.createNewFile()) {
        try (final FileOutputStream fos = new FileOutputStream(archiefBestand);
             final BufferedOutputStream bos = new BufferedOutputStream(fos)) {
            int len;
            byte[] buffer = new byte[BUFFER_SIZE];
            while ((len = archiefStream.read(buffer)) > 0) {
                bos.write(buffer, 0, len);
            }
            bos.flush();
        }
    }
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:17,代码来源:TimestampMojo.java

示例3: getBytes

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
private byte[] getBytes(JarInputStream jis) throws IOException {
	int len = 0;
	byte[] bytes = new byte[8192];
	ByteArrayOutputStream baos = new ByteArrayOutputStream(2048);
	while ((len = jis.read(bytes, 0, bytes.length)) != -1) {
		baos.write(bytes, 0, len);
	}
	return baos.toByteArray();
}
 
开发者ID:crosg,项目名称:Albianj2,代码行数:10,代码来源:AlbianClassLoader.java

示例4: getBytes

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
/**
 * ��jar�������ж�ȡ��Ϣ
 * 
 * @param jis
 * @return
 * @throws IOException
 */
private byte[] getBytes(JarInputStream jis) throws IOException {
	int len = 0;
	byte[] bytes = new byte[8192];
	ByteArrayOutputStream baos = new ByteArrayOutputStream(2048);
	while ((len = jis.read(bytes, 0, bytes.length)) != -1) {
		baos.write(bytes, 0, len);
	}
	return baos.toByteArray();
}
 
开发者ID:crosg,项目名称:Albianj2,代码行数:17,代码来源:AlbianJarEncoder.java

示例5: JarLoader

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
/**
 * Creates a loader to load a specified JAR file.
 *
 * We place no restrictions on what the <code>URL</code> points to here.
 * instead any access restrictions (from trusted java) are enforced by
 * the <code>Security Manager</code> defined in <code>Backend.java</code>.
 *
 * @param url : The URL to load
 * @return JarLoader : Classloader for a specified JAR
 * @throws IOException : when the Jar cannot be read
 *
 */
JarLoader(ClassLoader parent, URL url) throws IOException
{
	super(parent);

	m_url = url;
	m_entries = new HashMap();
	m_images  = new HashMap();

	// Just having a JAR in your CLASSPATH will cause us to load it,
	// which means you need security access to it.
	JarInputStream jis = new JarInputStream(url.openStream());
	ByteArrayOutputStream img = new ByteArrayOutputStream();
	byte[] buf = new byte[1024];
	JarEntry je;
	for (je = jis.getNextJarEntry();
		 je != null;
		 je = jis.getNextJarEntry())
	{
		if (je.isDirectory())
			continue;
		String entryName = je.getName();
		Attributes attr = je.getAttributes();
		int nBytes;

		img.reset();
		while ((nBytes = jis.read(buf)) > 0)
			img.write(buf, 0, nBytes);
		jis.closeEntry();

		m_entries.put(entryName, img.toByteArray());
	}
	m_manifest = jis.getManifest();
}
 
开发者ID:greenplum-db,项目名称:pljava,代码行数:46,代码来源:JarLoader.java

示例6: fetch

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
/**
 * Fetches the game jar and loads and patches the classes
 * 
 * @param jarURL The URL of the jar to be loaded and patched
 * @return If no exceptions occurred
 */
public boolean fetch(String jarURL) {
	Logger.Info("Fetching Jar: " + jarURL);
	
	try {
		JarInputStream in = new JarInputStream(Settings.getResourceAsStream(jarURL));
		Launcher.getInstance().setProgress(1, 1);
		
		JarEntry entry;
		while ((entry = in.getNextJarEntry()) != null) {
			// Check if file is needed
			String name = entry.getName();
			
			// Read class to byte array
			ByteArrayOutputStream bOut = new ByteArrayOutputStream();
			byte[] data = new byte[1024];
			int readSize;
			while ((readSize = in.read(data, 0, data.length)) != -1)
				bOut.write(data, 0, readSize);
			byte[] classData = bOut.toByteArray();
			bOut.close();
			
			Logger.Info("Loading file: " + name);
			Launcher.getInstance().setStatus("Loading " + name + "...");
			
			if (name.endsWith(".class")) {
				name = name.substring(0, name.indexOf(".class"));
				classData = JClassPatcher.getInstance().patch(classData);
				m_classData.put(name, classData);
			}
		}
		in.close();
	} catch (Exception e) {
		e.printStackTrace();
		return false;
	}
	return true;
}
 
开发者ID:OrN,项目名称:rscplus,代码行数:44,代码来源:JClassLoader.java

示例7: unjar

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
/**
 * Given an InputStream on a jar file, unjars the contents into the given
 * directory.
 */
public void unjar(InputStream in, File destDir) throws IOException {
	BufferedOutputStream dest = null;
	JarInputStream jis = new JarInputStream(in);
	JarEntry entry;
	while ((entry = jis.getNextJarEntry()) != null) {
		if (entry.isDirectory()) {
			File dir = new File(destDir, entry.getName());
			dir.mkdir();
			if (entry.getTime() != -1) {
				dir.setLastModified(entry.getTime());
			}
			continue;
		}
		int count;
		byte[] data = new byte[BUFFER_SIZE];
		File destFile = new File(destDir, entry.getName());
		if (mVerbose) {
			System.out.println("unjarring " + destFile +
				" from " + entry.getName());
		}
		FileOutputStream fos = new FileOutputStream(destFile);
		dest = new BufferedOutputStream(fos, BUFFER_SIZE);
		try {
			while ((count = jis.read(data, 0, BUFFER_SIZE)) != -1) {
				dest.write(data, 0, count);
			}
			dest.flush();
		} finally {
			dest.close();
		}
		if (entry.getTime() != -1) {
			destFile.setLastModified(entry.getTime());
		}
	}
	jis.close();
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:41,代码来源:JarHelper.java

示例8: rewrite

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
private static File rewrite(File jar, String[] mavenCP, String classpath) throws IOException { // #190992
    String[] classpathEntries = tokenizePath(classpath);
    StringBuilder classPathHeader = new StringBuilder();
    for (String artifact : mavenCP) {
        String[] grpArtVers = artifact.split(":");
        String partOfPath = File.separatorChar + grpArtVers[0].replace('.', File.separatorChar) + File.separatorChar + grpArtVers[1] + File.separatorChar + grpArtVers[2] + File.separatorChar + grpArtVers[1] + '-' + grpArtVers[2];
        File dep = null;
        for (String classpathEntry : classpathEntries) {
            if (classpathEntry.endsWith(".jar") && classpathEntry.contains(partOfPath)) {
                dep = new File(classpathEntry);
                break;
            }
        }
        if (dep == null) {
            throw new IOException("no match for " + artifact + " found in " + classpath);
        }
        File depCopy = File.createTempFile(artifact.replace(':', '-') + '-', ".jar");
        depCopy.deleteOnExit();
        NbTestCase.copytree(dep, depCopy);
        if (classPathHeader.length() > 0) {
            classPathHeader.append(' ');
        }
        classPathHeader.append(depCopy.getName());
    }
    String n = jar.getName();
    int dot = n.lastIndexOf('.');
    File jarCopy = File.createTempFile(n.substring(0, dot) + '-', n.substring(dot));
    jarCopy.deleteOnExit();
    InputStream is = new FileInputStream(jar);
    try {
        OutputStream os = new FileOutputStream(jarCopy);
        try {
            JarInputStream jis = new JarInputStream(is);
            Manifest mani = new Manifest(jis.getManifest());
            mani.getMainAttributes().putValue("Class-Path", classPathHeader.toString());
            JarOutputStream jos = new JarOutputStream(os, mani);
            JarEntry entry;
            while ((entry = jis.getNextJarEntry()) != null) {
                if (entry.getName().matches("META-INF/.+[.]SF")) {
                    throw new IOException("cannot handle signed JARs");
                }
                jos.putNextEntry(entry);
                byte[] buf = new byte[4092];
                for (;;) {
                    int more = jis.read(buf, 0, buf.length);
                    if (more == -1) {
                        break;
                    }
                    jos.write(buf, 0, more);
                }
            }
            jis.close();
            jos.close();
        } finally {
            os.close();
        }
    } finally {
        is.close();
    }
    return jarCopy;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:62,代码来源:NbModuleSuite.java

示例9: generateUnhide

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
public static String generateUnhide(Context context, File output) {
    File temp = new File(context.getCacheDir(), "temp.apk");
    String pkg = "";
    Log.d(TAG, "try start ");
    try {
        JarInputStream source = new JarInputStream(new FileInputStream(new File(Tools.runCommand("pm path " + ISU_APK + "| head -n1 | cut -d: -f2", Tools.SuBinary(), context))));
        JarOutputStream dest = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(temp)));
        JarEntry entry;
        int size;
        byte buffer[] = new byte[4096];
        while ((entry = source.getNextJarEntry()) != null) {
            dest.putNextEntry(new JarEntry(entry.getName()));
            if (TextUtils.equals(entry.getName(), ANDROID_MANIFEST)) {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                while ((size = source.read(buffer)) > 0) {
                    baos.write(buffer, 0, size);
                }

                byte xml[] = baos.toByteArray();
                boolean need_zero = false;
                int offset = Tools.FindOffSet(xml, COM_PKG_NAME);

                if (offset < 0) {
                    Log.d(TAG, "offset < 0 try appModZeros");
                    byte[] COM_PKG_NAME_ZERO = (Tools.appStringAddZeros(app_name)).getBytes();
                    offset = Tools.FindOffSet(xml, COM_PKG_NAME_ZERO);
                    need_zero = true;
                }
                if (offset < 0) {
                    Log.d(TAG, "offset < 0 again return");
                    return "";
                }

                Log.d(TAG, "offset " + offset + " leg " + COM_PKG_NAME.length);
                // Patch binary XML with new package name
                if (Tools.appInstaled(context)) {
                    if (need_zero)
                        pkg = Tools.appStringAddZeros(Tools.readString("hide_app_name", null, context));
                    else
                        pkg = Tools.readString("hide_app_name", null, context);
                } else
                    pkg = Tools.appStringMod(app_name, need_zero);
                System.arraycopy(pkg.getBytes(), 0, xml, offset, pkg.length());
                dest.write(xml);
            } else {
                while ((size = source.read(buffer)) > 0) {
                    dest.write(buffer, 0, size);
                }
            }
        }
        source.close();
        dest.close();
        signZip(context, temp, output, false);
        temp.delete();
    } catch (IOException e) {
        e.printStackTrace();
        return pkg;
    }
    Log.d(TAG, "pkg " + pkg.replace("\0", ""));
    return pkg;
}
 
开发者ID:bhb27,项目名称:isu,代码行数:62,代码来源:ZipUtils.java

示例10: main

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
public static final void main( String[] args ) throws IOException {

        if ( args.length != 2 ) {
            System.out.println( "usage: TestJarInsert jarFile insertFile" );
            System.exit( 1 );
        }
        String jarFileName = args[0];
        String insertFileName = args[1];

        // the file to insert
        File insertFile = new File( insertFileName );
        InputStream insertStream = new FileInputStream( insertFile );

        // the original JAR file
        File jarFile = new File( jarFileName );
        JarInputStream jarStream = new JarInputStream( new FileInputStream( jarFile ) );
        Manifest manifest = jarStream.getManifest();
        if ( manifest == null ) {
            System.out.println( "JAR file is missing manifest" );
            System.exit( 1 );
        }

        // output goes to a temp JAR file
        String tmpFileName = jarFileName + ".tmp";
        File tmpFile = new File( tmpFileName );
        JarOutputStream tmpStream = new JarOutputStream( new FileOutputStream( tmpFile ), manifest );

        byte[] buffer = new byte[1024];
        int bytesRead;
        
        // copy all entries from input to output, skipping the insert file if it already exists
        JarEntry jarEntry = jarStream.getNextJarEntry();
        while ( jarEntry != null ) {
            if ( !jarEntry.getName().equals( insertFileName ) ) {
                tmpStream.putNextEntry( jarEntry );
                while ( ( bytesRead = jarStream.read( buffer ) ) > 0 ) {
                    tmpStream.write( buffer, 0, bytesRead );
                }
            }
            jarEntry = jarStream.getNextJarEntry();
        }

        // add properties file to output
        jarEntry = new JarEntry( insertFileName );
        tmpStream.putNextEntry( jarEntry );
        while ( ( bytesRead = insertStream.read( buffer ) ) != -1 ) {
            tmpStream.write( buffer, 0, bytesRead );
        }

        // close the streams
        insertStream.close();
        jarStream.close();
        tmpStream.close();

        // if everything went OK, move tmp file to JAR file
        boolean renameSuccess = tmpFile.renameTo( jarFile );
        if ( !renameSuccess ) {
            System.err.println( "failed to rename " + tmpFileName + " to " + jarFileName );
            System.exit( 1 );
        }
    }
 
开发者ID:mleoking,项目名称:PhET,代码行数:62,代码来源:TestJarInsert.java

示例11: readPatchEntries

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
protected void
readPatchEntries(
	InputStream		is )

	throws IOException
{
	JarInputStream	jis = new JarInputStream(is );

	while( true ){

		JarEntry ent = jis.getNextJarEntry();

		if ( ent == null ){

			break;
		}

		if ( ent.isDirectory()){

			continue;
		}

		ByteArrayOutputStream	baos = new ByteArrayOutputStream();

		byte[]	buffer = new byte[8192];

		while( true ){

			int	l = jis.read( buffer );

			if ( l <= 0 ){

				break;
			}

			baos.write( buffer, 0, l );
		}

		patch_entries.put( ent.getName(), new ByteArrayInputStream( baos.toByteArray()));
	}
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:42,代码来源:UpdateJarPatcher.java

示例12: readPatchEntries

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
protected void
readPatchEntries(
	InputStream		is )

	throws IOException
{
	JarInputStream	jis = new JarInputStream(is );
		
	while( true ){
		
		JarEntry ent = jis.getNextJarEntry();
		
		if ( ent == null ){
			
			break;
		}
		
		if ( ent.isDirectory()){
			
			continue;
		}
		
		ByteArrayOutputStream	baos = new ByteArrayOutputStream();
			
		byte[]	buffer = new byte[8192];
			
		while( true ){
				
			int	l = jis.read( buffer );
				
			if ( l <= 0 ){
					
				break;
			}
				
			baos.write( buffer, 0, l );
		}
			
		patch_entries.put( ent.getName(), new ByteArrayInputStream( baos.toByteArray()));
	}
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:42,代码来源:UpdateJarPatcher.java


注:本文中的java.util.jar.JarInputStream.read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。