Read image data to byte [] array, combined inputStream to read generated each time a buffer byte []

2010-05-29  来源:本站原创  分类:Java  人气:573 

First time writing.

Just write the binary form of a picture to read the byte [] array to the procedure, there is a problem: cycles InputStream.read (byte [] buffer), each read a certain amount of bytes (the number of unknown) data, the buffer will be an unprecedented array of clean, so must be the buffer to save time, the final will all be combined into a total buffer of the buffer array, just realized, fear of forgetting, feel the need to record look!

image object has three attributes, id, name and content, types are: int, String, byte []

InputStream is = fileItem.getInputStream ();

Image image = new Image ();
image.setId (9);
image.setName (fileItem.getName ());

byte [] buffer = new byte [1024 * 50];
int length = 0;
int lastLength = 0;
byte [] totalBuffer = new byte [1024 * 50];

for (lastLength = length; (length = is.read (buffer))> 0;) (
System.arraycopy (buffer, 0, totalBuffer, lastLength, length);
)

is.close ();

image.setContent (totalBuffer);

This is a major, the other file upload is not like that, and there's really nothing!

相关文章
  • Read image data to byte [] array, combined inputStream to read generated each time a buffer byte [] 2010-05-29

    First time writing. Just write the binary form of a picture to read the byte [] array to the procedure, there is a problem: cycles InputStream.read (byte [] buffer), each read a certain amount of bytes (the number of unknown) data, the buffer will be

  • Byte array input stream ByteArrayInputStream 2010-12-05

    ByteArrayInputSteam class array of bytes from memory to read data, so its data source is a byte array. Constructor of this class include: ByteArrayInputStream (byte [] buf )-------- parameter type of the specified byte array buf the data source. Byte

  • August 27, 2010 --- RedDwarf as data communication between server and when the byte array type to other types of data conversion 2010-08-27

    Engage in this because: RedDwarf way server platform is based on byte array of data types, so need to do a byte array to convert basic data types. The main technology used MINA and AMF, the first to introduce the AMF: Action Message Format (AMF) is a

  • Byte [] array of other data type conversion between 2010-07-22

    Byte [] array of other data type conversion between //Byte[] Arrays and other data type conversions // Through the BitConverter class implements the // Take an int to byte[] byte[] arrayByte = BitConverter.GetBytes(10); // The byte[] Go to integer by

  • javamail send a file attachment (see annex for the byte array) 2009-10-01

    In the actual development, we often encounter the need to go through the procedure to send e-mail problem, and we are now using more than is javamail, we know that javamail to send a local attachment is very easy, but if the attachment is stored in a

  • The Image of the png format, as converted to byte array 2010-04-15

    Principle, said 1 Image of ARGB data access 2 will convert ARGB PNG format stored using the RGBA 3RGBA format of data processing still done little behind each line plus a byte 0 4 ways to use LZ77 compression array of RGBA format 5 Add the right outp

  • java binary, byte array, character, hexadecimal, BCD code conversion 2010-07-29

    * The hex string into byte array * @param hex * @return */ public static byte[] hexStringToByte(String hex) { int len = (hex.length() / 2); byte[] result = new byte[len]; char[] achar = hex.toCharArray(); for (int i = 0; i < len; i++) { int pos = i *

  • long and byte array conversion 2010-08-14

    Example: Type ----> byte long array long n = 1000000L; // The output stream, the data is written to a byte Array, the available toByteArray(),toString() Gets the data ByteArrayOutputStream bos = new ByteArrayOutputStream(); // Note the ByteArrayOutpu

  • VB byte array and string conversion (String <> Byte) 2011-03-09

    I. Introduction Data type conversion is often used in programming, VB6 provides a set of type conversion functions. However, during the type conversion, sometimes relying on VB to provide the function can not achieve their purpose. Therefore, the nee

  • Parsing and Formatting a Byte Array into Binary, Octal, and Hexadecimal 2010-03-29

    // Get a byte array byte[] bytes = new byte[]{(byte)0x12, (byte)0x0F, (byte)0xF0}; // Create a BigInteger using the byte array BigInteger bi = new BigInteger(bytes); // Format to binary String s = bi.toString(2); // 100100000111111110000 // Format to

  • silverlight into how to BitmapImage Stream or byte array? 2010-04-21

    Disclaimer: This article is reproduced from: http://www.cnblogs.com/yjmyzz/archive/2010/01/15/1648317.html On a " base64 encoding used in the silverlight "had already been mentioned WriteableBitmap object can be converted to base64 string with F

  • C + + is simple to read and write text files. Statistical file lines. Read file data into an array 2011-05-09

    fstream provides three classes used to implement c + + file operations. (File creation, reading and writing). ifstream - read from existing file ofstream - write to the file contents fstream - Open the file for read and write File open mode: ios:: in

  • Byte array is converted to hexadecimal string 2009-12-19

    /** * Converts an array of bytes into a string of hexadecimal characters * @param datas byte[] To convert the data * @return String The converted data */ public static String bytes2HexString(byte[] datas) { StringBuilder sb = new StringBuilder(""

  • Oracle objects - abstract data types. Variable array. Nested table. Object tables and object views 2010-02-23

    Oracle Database is RDBMS (relational database) is ORDBMS (object-oriented database). RDBMS: When reusing a function, will need to be compiled; ORDBMS: allows you to define object types; in a relational database to store complex business models; devel

  • BufferedImage byte array conversion 2010-10-10

    import java.io.ByteArrayOutputStream; import com.sun.image.codec.jpeg.ImageFormatException; import com.sun.image.codec.jpeg.JPEGCodec; import com.sun.image.codec.jpeg.JPEGImageEncoder; import java.io.IOException; public static byte[] bufferedImageToB

  • float and byte array conversion, d lang V1 2010-10-26

    import tango.io.Stdout; void ConvertFloatToBytes(float Value,inout byte[] Bytes) { uint ByteVal1, ByteVal2, ByteVal3, ByteVal4; asm { mov EAX, Value; and EAX, 0xFF000000; shr EAX, 24; mov ByteVal1, EAX; mov EAX, Value; and EAX, 0x00FF0000; shr EAX, 1

  • VB longs, and byte array conversion (Long <> Byte) 2011-03-09

    Use the API declaration: Private Declare Sub CopyMemory Lib "kernel32" Alias ​​"RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) Long2Byte Dim TempLng As Long Dim TempBytes (0 To 3) As Byte TempLng = 2000 # If m

  • [POI-HSSF] byte array of documents generated HSSFWorkbook 2010-07-21

    Wrong wording is: return workbook.getBytes(); Wording is correct: ByteArrayOutputStream out = new ByteArrayOutputStream(); workbook.write(out); return out.toByteArray();

  • Data transfer some of the methods used 2010-05-08

    Enter replace Tab with #region Use enter to replace Tab private void AccessoryInfo_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Enter) { if ((this.ActiveControl is TextBox)) SendKeys.Send("{TAB}"); e.Handled = true;

  • Java Best Practices - Char to Byte and Byte to Char conversions 2010-11-09

    Java Best Practices - Char to Byte and Byte to Char conversions From Java Code Geeks of: Justin Cater 1 people like this entry Continuing our series of articles concerning proposed practices while working with the Java programming language, we are go