Package java.io

Examples of java.io.ByteArrayInputStream


   /**
    *  Write a byte array to a file.
    */
    public static void write(byte[] data, String fileName) throws IOException {
        ByteArrayInputStream bais = null;
        InputStream is = null;
        try {
            bais = new ByteArrayInputStream(data);
            is = new BufferedInputStream(bais);
   
            write(is, fileName)
        } finally {
            if (is != null) {
                is.close();
            }
            if (bais != null) {
                bais.close();
            }
        }
    }
View Full Code Here


  /**
   *  Write a byte array to a file.
   */
   public static void write(byte[] data, File file) throws IOException {
         ByteArrayInputStream bais = null;
         InputStream is = null;
         try {
         bais = new ByteArrayInputStream(data);
         is = new BufferedInputStream(bais);
   
         write(is, file)
         } finally {
             if (is != null) {
                 is.close();
             }
             if (bais != null) {
                 bais.close();
             }
         }
   }
View Full Code Here

@SuppressWarnings("nls")
public class TestInputStreamReader {

  @Test public void testMultiByte() throws Exception {
    InputStreamReader isr = new InputStreamReader(new ByteArrayInputStream(new byte[] {(byte)80, (byte)-61, (byte)-70}), Charset.forName("UTF-8").newDecoder(), 2);
    assertEquals(80, isr.read());
    assertEquals(250, isr.read());
  }
View Full Code Here

      }

      if (awtImage != null) {
        final ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        ImageIO.write((BufferedImage) awtImage, "png", outStream);
        final ByteArrayInputStream inStream = new ByteArrayInputStream(
            outStream.toByteArray());

        image = new Image(Display.getDefault(), inStream);
        if (!bBig) {
          image = force16height(image);
View Full Code Here

    pis.connect( pos );
   
    input_stream  = pis;
    output_stream   = pos;
   
    MagnetURIHandler.getSingleton().process( get, new ByteArrayInputStream(new byte[0]), pos );
  }
View Full Code Here

  }
 
  private Throwable readFromByteArray(byte[] contents) {
    // only for top level we would have the contents as not null.
    if (contents != null) {
      ByteArrayInputStream bais = new ByteArrayInputStream(contents);
      try {
        ObjectInputStream ois = new ObjectInputStreamWithClassloader(bais, ExceptionHolder.class.getClassLoader());
        return (Throwable)ois.readObject();
      } catch (Exception e) {
        //
View Full Code Here

public class TestByteLobChunkStream extends TestCase {

    public void testGetChunk() throws Exception {
      byte[] bytes = "hello world".getBytes(); //$NON-NLS-1$
        ByteLobChunkStream stream = new ByteLobChunkStream(new ByteArrayInputStream(bytes), 5);

        assertTrue(Arrays.equals(bytes, ObjectConverterUtil.convertToByteArray(new LobChunkInputStream(stream))));           
    }
View Full Code Here

  }

  @Test public void testLobs() throws Exception {
    SocketServerConnection conn = helpEstablishConnection(false);
    FakeService fs = conn.getService(FakeService.class);
    assertEquals(150, fs.lobMethod(new ByteArrayInputStream(new byte[100]), new StringReader(new String(new char[50]))));
    assertEquals(2, storageManager.getCreated());
    assertEquals(2, storageManager.getRemoved());
    assertEquals(0, fs.lobMethod(new ByteArrayInputStream(new byte[0]), new StringReader(new String(new char[0]))));
    assertEquals(4, storageManager.getCreated());
    assertEquals(4, storageManager.getRemoved());
    assertEquals((1 << 17) + 50, fs.lobMethod(new ByteArrayInputStream(new byte[1 << 17]), new StringReader(new String(new char[50]))));
    assertEquals(6, storageManager.getCreated());
    assertEquals(6, storageManager.getRemoved());
  }
View Full Code Here

          if (labelFile.getParent() instanceof IFolder) {
            IFolder parentFolder = (IFolder) labelFile.getParent();
            parentFolder.create(false, true, new NullProgressMonitor());
          }
        }
        ByteArrayInputStream byteStream = new ByteArrayInputStream("".getBytes());
        labelFile.create(byteStream, true, new NullProgressMonitor());
       
      } catch (CoreException e) {
        Activator.getDefault().getLog().log(new Status(Status.ERROR, Activator.PLUGIN_ID, "Can't create propertyfile : " + labelFile.getLocation(), e));
      }      
View Full Code Here

     
    IResource portletFolderResource = FileUtils.createFolder(parent, portletName);
    IFolder portletFolder = (IFolder) portletFolderResource;     
   
    String tmlInclude = header + "\n<tml:include ref=\"{'::mode-' + portlet.mode}\"/>";   
    ByteArrayInputStream input = new ByteArrayInputStream(tmlInclude.getBytes());
    IFile portletFile = portletFolder.getFile("portlet.tml");
    portletFile.create(input, true, new NullProgressMonitor());
   
    portletFolder.getFile("form.tml").create(new ByteArrayInputStream(header.getBytes()), true, new NullProgressMonitor());   
    //TODO Form for form.tml
   
   
   
    Iterator<String> it = modes.iterator();   
    while (it.hasNext()) {
      String current = it.next();
      portletFolder.getFile("mode-"+current+".tml").create(new ByteArrayInputStream(header.getBytes()), true, new NullProgressMonitor());     
    }   
    return portletFile;
  }
View Full Code Here

TOP

Related Classes of java.io.ByteArrayInputStream

Copyright © 2015 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.