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


Java Streams类代码示例

本文整理汇总了Java中org.jboss.forge.furnace.util.Streams的典型用法代码示例。如果您正苦于以下问题:Java Streams类的具体用法?Java Streams怎么用?Java Streams使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Streams类属于org.jboss.forge.furnace.util包,在下文中一共展示了Streams类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getServiceRegistry

import org.jboss.forge.furnace.util.Streams; //导入依赖的package包/类
@Override
public ServiceRegistry getServiceRegistry(Addon addon) throws Exception
{
   URL resource = addon.getClassLoader().getResource("/META-INF/services/" + SERVICE_REGISTRATION_FILE_NAME);
   Set<Class<?>> serviceTypes = new HashSet<Class<?>>();
   if (resource != null)
   {
      InputStream stream = resource.openStream();
      String services = Streams.toString(stream);
      for (String serviceType : services.split("\n"))
      {
         if (ClassLoaders.containsClass(addon.getClassLoader(), serviceType))
         {
            Class<?> type = ClassLoaders.loadClass(addon.getClassLoader(), serviceType);
            serviceTypes.add(type);
         }
      }

   }
   return new ReflectionServiceRegistry(furnace, addon, serviceTypes);
}
 
开发者ID:forge,项目名称:furnace,代码行数:22,代码来源:LocalServices.java

示例2: toDOT

import org.jboss.forge.furnace.util.Streams; //导入依赖的package包/类
public void toDOT(File file)
{
   FileWriter fw = null;
   try
   {
      DOTExporter<AddonVertex, AddonDependencyEdge> exporter = new DOTExporter<AddonVertex, AddonDependencyEdge>(
               new IntegerNameProvider<AddonVertex>(),
               new AddonVertexNameProvider(),
               new AddonDependencyEdgeNameProvider());

      fw = new FileWriter(file);
      exporter.export(fw, graph);
      fw.flush();
   }
   catch (IOException e)
   {
      e.printStackTrace();
   }
   finally
   {
      Streams.closeQuietly(fw);
   }
}
 
开发者ID:forge,项目名称:furnace,代码行数:24,代码来源:MasterGraph.java

示例3: saveRegistryFile

import org.jboss.forge.furnace.util.Streams; //导入依赖的package包/类
private void saveRegistryFile(Node installed) throws FileNotFoundException
{
   FileOutputStream outStream = null;
   try
   {
      outStream = new FileOutputStream(getRepositoryRegistryFile());
      incrementVersion();
      Streams.write(XMLParser.toXMLInputStream(installed), outStream);
   }
   finally
   {
      Streams.closeQuietly(outStream);
   }
}
 
开发者ID:forge,项目名称:furnace,代码行数:15,代码来源:AddonRepositoryStateStrategyImpl.java

示例4: getAddonDescriptor

import org.jboss.forge.furnace.util.Streams; //导入依赖的package包/类
@Override
public File getAddonDescriptor(final AddonId addon)
{
   return lock.performLocked(LockMode.READ, new Callable<File>()
   {
      @Override
      public File call() throws Exception
      {
         File descriptorFile = getAddonDescriptorFile(addon);
         try
         {
            if (!descriptorFile.exists())
            {
               descriptorFile.mkdirs();
               descriptorFile.delete();
               descriptorFile.createNewFile();

               FileOutputStream stream = null;
               try
               {
                  stream = new FileOutputStream(descriptorFile);
                  Streams.write(XMLParser.toXMLInputStream(XMLParser.parse("<addon/>")), stream);
               }
               finally
               {
                  Streams.closeQuietly(stream);
               }
            }
            return descriptorFile;
         }
         catch (Exception e)
         {
            throw new RuntimeException("Error initializing addon descriptor file.", e);
         }
      }
   });
}
 
开发者ID:forge,项目名称:furnace,代码行数:38,代码来源:AddonRepositoryStorageStrategyImpl.java

示例5: getRepositoryRegistryFile

import org.jboss.forge.furnace.util.Streams; //导入依赖的package包/类
private File getRepositoryRegistryFile()
{
   return lock.performLocked(LockMode.READ, new Callable<File>()
   {
      @Override
      public File call() throws Exception
      {
         File registryFile = new File(getRootDirectory(), REGISTRY_DESCRIPTOR_NAME);
         try
         {
            if (!registryFile.exists())
            {
               registryFile.createNewFile();

               FileOutputStream out = null;
               try
               {
                  out = new FileOutputStream(registryFile);
                  Streams.write(XMLParser.toXMLInputStream(XMLParser.parse("<installed></installed>")), out);
               }
               finally
               {
                  Streams.closeQuietly(out);
               }
            }
            return registryFile;
         }
         catch (Exception e)
         {
            throw new RuntimeException("Error initializing addon registry file [" + registryFile + "]", e);
         }
      }
   });
}
 
开发者ID:koentsje,项目名称:forge-furnace,代码行数:35,代码来源:AddonRepositoryImpl.java

示例6: saveRegistryFile

import org.jboss.forge.furnace.util.Streams; //导入依赖的package包/类
private void saveRegistryFile(Node installed) throws FileNotFoundException
{
   FileOutputStream outStream = null;
   try
   {
      // TODO need to replace this with actual file-system transactionality, but should work for the common case
      outStream = new FileOutputStream(getRepositoryRegistryFile());
      incrementVersion();
      Streams.write(XMLParser.toXMLInputStream(installed), outStream);
   }
   finally
   {
      Streams.closeQuietly(outStream);
   }
}
 
开发者ID:koentsje,项目名称:forge-furnace,代码行数:16,代码来源:AddonRepositoryImpl.java

示例7: unzipToFolder

import org.jboss.forge.furnace.util.Streams; //导入依赖的package包/类
/**
 * Unzip the given {@link File} to the specified directory.
 */
public static void unzipToFolder(File inputFile, File outputDir) throws IOException
{
    if (inputFile == null)
        throw new IllegalArgumentException("Argument inputFile is null.");
    if (outputDir == null)
        throw new IllegalArgumentException("Argument outputDir is null.");

    try (ZipFile zipFile = new ZipFile(inputFile))
    {
        Enumeration<? extends ZipEntry> entryEnum = zipFile.entries();
        while (entryEnum.hasMoreElements())
        {
            ZipEntry entry = entryEnum.nextElement();
            String entryName = entry.getName();
            File destFile = new File(outputDir, entryName);
            if (!entry.isDirectory())
            {
                File parentDir = destFile.getParentFile();
                if (!parentDir.isDirectory() && !parentDir.mkdirs())
                {
                    throw new WindupException("Unable to create directory: " + parentDir.getAbsolutePath());
                }
                try (InputStream zipInputStream = zipFile.getInputStream(entry))
                {
                    try (FileOutputStream outputStream = new FileOutputStream(destFile))
                    {
                        Streams.write(zipInputStream, outputStream);
                    }
                }
            }
        }
    }
}
 
开发者ID:windup,项目名称:windup,代码行数:37,代码来源:ZipUtil.java

示例8: unzip

import org.jboss.forge.furnace.util.Streams; //导入依赖的package包/类
public static void unzip(File baseDir, Archive<?> archive)
{
   try
   {
      Map<ArchivePath, Node> content = archive.getContent(new Filter<ArchivePath>()
      {
         @Override
         public boolean include(ArchivePath object)
         {
            return object.get().endsWith(".jar");
         }
      });

      for (Entry<ArchivePath, Node> entry : content.entrySet())
      {
         ArchivePath path = entry.getKey();
         File target = new File(baseDir.getAbsolutePath() + "/" + path.get().replaceFirst("/lib/", ""));
         target.mkdirs();
         target.delete();
         target.createNewFile();

         Node node = entry.getValue();
         Asset asset = node.getAsset();
         FileOutputStream fos = null;
         InputStream is = null;
         try
         {
            fos = new FileOutputStream(target);
            is = asset.openStream();
            Streams.write(is, fos);
         }
         finally
         {
            Streams.closeQuietly(is);
            Streams.closeQuietly(fos);
         }
      }
   }
   catch (Exception e)
   {
      throw new RuntimeException(e);
   }
}
 
开发者ID:forge,项目名称:furnace,代码行数:44,代码来源:ShrinkWrapUtil.java

示例9: doCopyFile

import org.jboss.forge.furnace.util.Streams; //导入依赖的package包/类
/**
 * Internal copy file method.
 * 
 * @param srcFile the validated source file, must not be <code>null</code>
 * @param destFile the validated destination file, must not be <code>null</code>
 * @throws IOException if an error occurs
 */
private static void doCopyFile(File srcFile, File destFile) throws IOException
{
   if (destFile.exists() && destFile.isDirectory())
   {
      throw new IOException("Destination '" + destFile + "' exists but is a directory");
   }

   FileInputStream fis = null;
   FileOutputStream fos = null;
   FileChannel input = null;
   FileChannel output = null;
   try
   {
      fis = new FileInputStream(srcFile);
      fos = new FileOutputStream(destFile);
      input = fis.getChannel();
      output = fos.getChannel();
      long size = input.size();
      long pos = 0;
      long count = 0;
      while (pos < size)
      {
         count = (size - pos) > FIFTY_MB ? FIFTY_MB : (size - pos);
         pos += output.transferFrom(input, pos, count);
      }
   }
   finally
   {
      Streams.closeQuietly(output);
      Streams.closeQuietly(fos);
      Streams.closeQuietly(input);
      Streams.closeQuietly(fis);
   }

   if (srcFile.length() != destFile.length())
   {
      throw new IOException("Failed to copy full contents from '" +
               srcFile + "' to '" + destFile + "'");
   }
}
 
开发者ID:forge,项目名称:furnace,代码行数:48,代码来源:Files.java

示例10: deploy

import org.jboss.forge.furnace.util.Streams; //导入依赖的package包/类
@Override
public boolean deploy(final AddonId addon, final Iterable<AddonDependencyEntry> dependencies,
         final Iterable<File> resources)
{
   return lock.performLocked(LockMode.WRITE, new Callable<Boolean>()
   {
      @Override
      public Boolean call() throws Exception
      {
         File addonSlotDir = getAddonBaseDir(addon);
         File descriptor = getAddonDescriptor(addon);
         try
         {
            if (resources != null)
            {
               for (File resource : resources)
               {
                  if (resource.isDirectory())
                  {
                     String child = addon.getName()
                              + resource.getParentFile().getParentFile().getName();
                     child = OperatingSystemUtils.getSafeFilename(child);
                     Files.copyDirectory(resource, new File(addonSlotDir, child));
                  }
                  else
                  {
                     Files.copyFileToDirectory(resource, addonSlotDir);
                  }
               }
            }
            /*
             * Write out the addon module dependency configuration
             */
            Node addonXml = getXmlRoot(descriptor);
            Node dependenciesNode = addonXml.getOrCreate(DEPENDENCIES_TAG_NAME);

            if (dependencies != null)
            {
               for (AddonDependencyEntry dependency : dependencies)
               {
                  String name = dependency.getName();
                  Node dep = null;
                  for (Node node : dependenciesNode.get(DEPENDENCY_TAG_NAME))
                  {
                     if (name.equals(node.getAttribute(ATTR_NAME)))
                     {
                        dep = node;
                        break;
                     }
                  }
                  if (dep == null)
                  {
                     dep = dependenciesNode.createChild(DEPENDENCY_TAG_NAME);
                     dep.attribute(ATTR_NAME, name);
                  }
                  dep.attribute(ATTR_VERSION, dependency.getVersionRange());
                  dep.attribute(ATTR_EXPORT, dependency.isExported());
                  dep.attribute(ATTR_OPTIONAL, dependency.isOptional());
               }
            }

            FileOutputStream fos = null;
            try
            {
               fos = new FileOutputStream(descriptor);
               Streams.write(XMLParser.toXMLInputStream(addonXml), fos);
            }
            finally
            {
               Streams.closeQuietly(fos);
            }
            return true;
         }
         catch (IOException io)
         {
            io.printStackTrace();
            return false;
         }
      }
   });
}
 
开发者ID:koentsje,项目名称:forge-furnace,代码行数:82,代码来源:AddonRepositoryImpl.java


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